0

I am using eclipse luna and jdk 7. I am using tomcat server. I have written simple rest program by creating dynamic web project its working fine. I have created stand alone java program to test rest program i am getting following exception.

My REST Program

 @Path("/helloworld")
    public class test {
    // When client wants XML
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayHelloXML() { 
    return "<?xml version=\"1.0\"?>" + "<msg>" + "Hello World in REST" + " 
    </msg>";
    }
    Web. xml
    <servlet-mapping>
    <servlet-name>spring-ws-service</servlet-name>
    <url-pattern>/processXML</url-pattern>
    </servlet-mapping>
    <servlet>
    <servlet-name>Rest</servlet-name>
    <servlet-class>
    com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Rest</servlet-name>
    <url-pattern>/backend/*</url-pattern>
    </servlet-mapping>

When i check with url https://lcalhoast:8443/Phoenix/backend/helloworld I will get the output as Hello World in Rest.

I have created standalone java program s Rest client. This is the program

 public class Test {
    public static void main(String[] args) {
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client.resource(getBaseURI());
    System.out.println(service.path("backend").path("helloworld").accept(
    MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());    
    System.out.println(service.path("backend").path("helloworld").accept(
    MediaType.TEXT_XML).get(String.class));
    System.out.println(service.path("backend").path("helloworld").accept(
    MediaType.TEXT_HTML).get(String.class));
    }
    private static URI getBaseURI() {
    return UriBuilder.fromUri(
    "http://localhost:8443/Phoenix").build();
    }
    }
When i run client as java application. i am getting following ecxceptions

`Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException:

java.net.SocketException: Unexpected end of file from server
com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)
at cs9322.simple.rest.hello.client.Test.main(Test.java:22)
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:772)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:769)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)

I restarted server still getting same error since two days

Cœur
  • 37,241
  • 25
  • 195
  • 267
Govind Soraganvi
  • 81
  • 1
  • 1
  • 9
  • Your URLs are different other has HTTPS and other HTTP? – FrAn Jan 29 '15 at 07:25
  • Ya.. Thank you.. I changed it to https but i am getting following exception.Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found – Govind Soraganvi Jan 29 '15 at 07:39
  • You don't have HTTPS/TLS enabled on your localhost Tomcat? – FrAn Jan 29 '15 at 07:44
  • Maybe [this](http://stackoverflow.com/questions/25079751/ssl-certificate-verification-javax-net-ssl-sslhandshakeexception) will sed light some insight for the SSL exception – FrAn Jan 29 '15 at 07:53
  • I could not follow the link so i configured tomcat server to enable SSlconnection. I followed this tutorial. http://www.mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/ but still i am getting the same error – Govind Soraganvi Jan 29 '15 at 08:21

0 Answers0