java - HTTP 500 Internal Server Error in simple REST based program. Confused in GET and POST while receiving/sending response from server -


i implementing basic client server architecture using rest services first time. time making more complicated including more classes , services sharing class objects parameters between client , server. running server on apachetomcat7. getting executed successfully. when running client giving me error: javax.ws.rs.internalservererrorexception: http 500 internal server error tried debugging code, seems not receiving/sending response. know not wise idea share classes here has no choice since has wasted time lot. appreciated. in advance.

following imageprogress class. class present @ both server , client.

@xmlrootelement public class imageprogress{     private string name;      public imageprogress( string image_name){         this.name = image_name;     }      public string getname() {         return name;     }      public void setname( string name ){         this.name = name;     } } 

hpcresponse class object returned client server response. hpcresponse return imageprogress object give me intended result.

@xmlrootelement public class hpcresponse {     private imageprogress imgprogress;      public imageprogress getimgprogress() {         return imgprogress;     }      public void setimgprogress(imageprogress imgprogress) {         this.imgprogress = imgprogress;     } } 

following service class server named hpcservice return hpcresponse's object response. can see method startanalysing accepts object of hpcinfo. description of hpcinfo given below.

@path( "/hpc" ) @consumes( mediatype.application_xml ) @produces( mediatype.application_xml ) public class hpcservice{      public hpcinfo hpcinfo;     public hpcresponse hpcresponse;      @post     @path( "/analyze" )     public hpcresponse startanalysing(hpcinfo _hpcinfo){          system.out.println( "started analyzing..." );          hpcinfo = _hpcinfo;         hpcinfo.getimagepath();                  hpcresponse = new hpcresponse();         imageprogress iprog = new imageprogress(hpcinfo.getimagepath());         hpcresponse.setimgprogress(iprog);          system.out.println("returning response...");         return hpcresponse;     } } 

hpcinfo class @ both client , server. hpcinfo class:

    @xmlrootelement     public class hpcinfo     {         private string imagepath = "";          public string getimagepath(){             return imagepath;         }          public void setimagepath( string imagepath ){             this.imagepath = imagepath;         }     } 

and client calling hpcservice.

public class testclient {     private static string webserviceuri = "http://localhost:8080/testserver123";     public static void main(string[] args) {         string input = "abnkidney.scn";         clientconfig clientconfig = new clientconfig();         client client = clientbuilder.newclient(clientconfig);         uri serviceuri = uribuilder.fromuri(webserviceuri).build();          webtarget webtarget = client.target(serviceuri);          hpcinfo info = new hpcinfo();         info.setimagepath(input);          webtarget = webtarget.path("test").path("hpc").path("analyze");          hpcresponse hresponse = webtarget.request().accept(mediatype.application_xml).post(entity.entity(info, mediatype.application_xml), hpcresponse.class);     } } 

this full error description getting:

javax.ws.rs.internalservererrorexception: http 500 internal server error     @ org.glassfish.jersey.client.jerseyinvocation.converttoexception(jerseyinvocation.java:968)     @ org.glassfish.jersey.client.jerseyinvocation.translate(jerseyinvocation.java:795)     @ org.glassfish.jersey.client.jerseyinvocation.access$500(jerseyinvocation.java:91)     @ org.glassfish.jersey.client.jerseyinvocation$2.call(jerseyinvocation.java:683)     @ org.glassfish.jersey.internal.errors.process(errors.java:315)     @ org.glassfish.jersey.internal.errors.process(errors.java:297)     @ org.glassfish.jersey.internal.errors.process(errors.java:228)     @ org.glassfish.jersey.process.internal.requestscope.runinscope(requestscope.java:424)     @ org.glassfish.jersey.client.jerseyinvocation.invoke(jerseyinvocation.java:679)     @ org.glassfish.jersey.client.jerseyinvocation$builder.method(jerseyinvocation.java:435)     @ org.glassfish.jersey.client.jerseyinvocation$builder.post(jerseyinvocation.java:338)     @ com.testclient.main(testclient.java:34) 

this due imageprogress class not having default (no-arg) constructor. required jaxb.

one way debug things create simple exceptionmapper catch exceptions not mapped. when there no mapper, exception bubble container level, gives generic 500 server error (which of time of little help).

@provider public class debugexceptionmapper implements exceptionmapper<exception> {      @override     public response toresponse(exception exception) {         exception.printstacktrace();         return response.servererror().entity(exception.getmessage()).build();     }  } 

then register mapper. when running simple test imageprogress class, when exception thrown, stacktrace gets printed, , can see exception message

...imageprogress not have no-arg default constructor


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -