Showing posts with label webservice. Show all posts
Showing posts with label webservice. Show all posts

August 14, 2019

A short introduction to Web services - simple tutorial

What is a web service ?


  1. A web service enables communication among various applications by using open standards such as HTML, XML, JSON, WSDL, and SOAP.
  2. You can build a Java-based web service on Solaris that is accessible from your Visual Basic program that runs on Windows.
  3. You can also use C# to build new web services on Windows that can be invoked from your web application that is based on Java Server Pages (JSP) and runs on Linux.
  4. Here language is not a barrier, you can build web service in any language which can be consumed by any other language.


What is a XML RPC ?


  1. XML RPC is a platform Independent protocol that uses XML messages to perform RPCs.
  2. A Java client can communicate with Perl server through XML-RPC.
  3. XML responses are embedded in the body of the HTTP response.
  4. One of the easiest way to start a web service is using  XML-RPC.


Service Transport Layer


  1. Service Transport Layer in Web Service Protocol is responsible for transporting message between applications.
  2. This layer includes Hyper Text Transport Protocol (HTTP), Simple Mail Transfer Protocol (SMTP), File Transfer Protocol (FTP) and protocols such as Blocks Extensible Exchange Protocol ( BEEP).
  3. XML Messaging is responsible for encoding messages in a common XML format so that messages can be understood at either end ie Client as well as Server.


UDDI ( Universal Description Discovery and Integration)


  1. One of the three foundation standard of web services.
  2. Service Description is responsible for describing public interface to a specific web service.
  3. Service Requester is responsible for opening a connection and sending XML Request.
  4. Service Registry provides a central place where developers can publish new service or find the existing services.


SOAP ( Simple Object Access Protocol)


  1. SOAP is an XML based communication protocol for exchanging information between computers which helps applications to communicate each other.



Thanks to all.

Our suggestions


November 04, 2017

Comparing Java Webservices JAX-WS with Spring WS

Conclusion

 Considering contract-first web services, my little experience has driven me to choose JAX-WS in favor of Spring WS: testing benefits do not balance the ease-of-use of the standard. I must admit I was a little surprised by these results since most Spring components are easier to use and configure than their standard counterparts, but results are here.
  Link
 http://javabelazy.blogspot.in/

October 22, 2017

Real Time Currency Converter in java - Webservice

Currency Converter API (xe.com)


Description


some time instead of keeping currency rate converter static data in your local database is not at all feasible for your project. Yahoo is providing a free web sevices for currency rate converter similar to google xe.com. The below code will return the currency converting ratio

import java.io.IOException;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

/**
 *
 */

/**
 * @author currency conversion
 *
 */
public class DCSCurrencyConvertor {



/**
* @param args
* @throws IOException
* @throws HttpException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub;

DCSCurrencyConvertor convertor = new DCSCurrencyConvertor();
try {
String rate = convertor.convert("USD","AED");
System.out.println("USD to AED :"+rate);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





}

private String convert(String currencyFrom, String currencyTo) throws HttpException, IOException {
String currentRate = null;
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://quote.yahoo.com/d/quotes.csv?s=" + currencyFrom + currencyTo + "=X&f=l1&e=.csv");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    new DefaultHttpMethodRetryHandler(3, false));
int status = client.executeMethod(method);
System.out.println("status : "+status);

byte[] response = method.getResponseBody();
currentRate =new String(response);

return currentRate;
}

}

Jar files (Application Programming Interface)

commons-httpclient-3.1.jar
commons-codec-1.11.jar


Uri (Uniform Resource locator )


http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDEUR%22,%20%22USDJPY%22,%20%22USDBGN%22,%20%22USDCZK%22,%20%22USDDKK%22,%20%22USDGBP%22,%20%22USDHUF%22,%20%22USDLTL%22,%20%22USDLVL%22,%20%22USDPLN%22,%20%22USDRON%22,%20%22USDSEK%22,%20%22USDCHF%22,%20%22USDNOK%22,%20%22USDHRK%22,%20%22USDRUB%22,%20%22USDTRY%22,%20%22USDAUD%22,%20%22USDBRL%22,%20%22USDCAD%22,%20%22USDCNY%22,%20%22USDHKD%22,%20%22USDIDR%22,%20%22USDILS%22,%20%22USDINR%22,%20%22USDKRW%22,%20%22USDMXN%22,%20%22USDMYR%22,%20%22USDNZD%22,%20%22USDPHP%22,%20%22USDSGD%22,%20%22USDTHB%22,%20%22USDZAR%22,%20%22USDISK%22)&env=store://datatables.org/alltableswithkeys


Thanks to steffi for her support

August 15, 2017

Gzip compression working Spring MVC - Consumerfed

GZIP compression

public static String gzipCompression(String strNew) throws IOException {
    if (strNew == null || strNew.length() == 0) {
        return str;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(str.getBytes());
    gzip.close();
    String outStr = out.toString("UTF-8");
    return outStr;
 }


Using BufferedWriter

public static String compressString(String str) throws IOException{
if (str == null || str.length() == 0) {
    return str;
}

BufferedWriter writer = null;

try{
    File file =  new File("your.gzip")
    GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream(file));

    writer = new BufferedWriter(new OutputStreamWriter(zip, "UTF-8"));

    writer.append(str);
}
finally{        
    if(writer != null){
     writer.close();
     }
  }
 }


Using compression filter

package : com.planetj.servlet.filter.compression
spring compression filter


How to enable HTTP response compression

Read 69.18

http://docs.spring.io/spring-boot/docs/1.3.x/reference/htmlsingle/#how-to-enable-http-response-compression

GZip compression in spring

http://www.oodlestechnologies.com/blogs/Gzip-Servlet-Filter-in-Spring-MVC

Handling filters in spring MVC

https://www.mkyong.com/spring-mvc/how-to-register-a-servlet-filter-in-spring-mvc/

Working with @controllerAdvice and ResponseAdvice in spring 4

https://sdqali.in/blog/2016/06/08/filtering-responses-in-spring-mvc/

Interceptors

Interceptors are use to manipulate entities like inputstream and outputstreams. There are two kinds of interceptors ReaderInterceptor and WriterInterceptors


public class GzipWriterInterceptor implements writerinterceptors {
@override
public void aroundwriteto(writerinterceptorcontext context){
outputstream os = context.getoutputstream();
context.setoutputstream(new Gzipoutputsream(os));
context.proceed();
}
}


Using ResponseWrapper

https://stackoverflow.com/questions/25020331/spring-mvc-how-to-modify-json-response-sent-from-controller

@Override
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {

    ResponseWrapper responseWrapper = new ResponseWrapper((HttpServletResponse) response);

    chain.doFilter(request, responseWrapper);

    String responseContent = new String(responseWrapper.getDataStream());

    RestResponse fullResponse = new RestResponse(/*status*/, /*message*/,responseContent);

    byte[] responseToSend = restResponseBytes(fullResponse);

    response.getOutputStream().write(responseToSend);

}


using response body advice

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvice.html

@controllerAdvice +  implements ResponseBodyAdvice<Object>

https://mtyurt.net/2015/07/20/spring-modify-response-headers-after-processing/

@ControllerAdvice
public class HeaderModifierAdvice implements ResponseBodyAdvice<Object> {

    @Override
    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
        return true;
    }

    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
        response.getHeaders().add("dummy-header","dummy-value");
        return body;
    }
}


Rest Easy spring integration

http://www.concretepage.com/spring-4/spring-4-resteasy-3-jackson-json-integration-example-with-tomcat




June 10, 2017

Web Service Definition Language - WSDL tutorial

Working with Web Services in Java





Problems and Its Solutions


The Web service is already in use. Use a class customization to resolve this conflict

use -B-XautoNameResoulution while generating class from wsdl.
wsimport -keep -verbose -B-XautoNameResolution cfedStock.wsdl

http://javabelazy.blogspot.in/

Facebook comments