java - HTTP 500 error failed with 200 status code -



java - HTTP 500 error failed with 200 status code -

i have developed jax-rs project , called rest service add together info database. when sending post request add together data, gives 200 status code, adds info database , additionally gives 500 status says internal server error.

below jax-rs code.

@post @path("/users/add/") @produces("text/plain") public response adduser( @queryparam("userid") string userid, @queryparam("username") string username, @queryparam("userrole") string userrole, @queryparam("email") string email, @queryparam("password") string password, @queryparam("phone") string phone) { system.out.println("----invoking adduser"); try{ httpclient = new defaulthttpclient(); httppost postrequest = new httppost("http://appserver.dev.cloud.wso2.com/services/t/madusanka/projecttrackerdb-default-snapshot/adduser"); postrequest.addheader("accept", "application/xml"); list namevaluepairs = new arraylist(); namevaluepairs.add(new basicnamevaluepair("userid",userid)); namevaluepairs.add(new basicnamevaluepair("username",username)); namevaluepairs.add(new basicnamevaluepair("userrole",userrole)); namevaluepairs.add(new basicnamevaluepair("email",email)); namevaluepairs.add(new basicnamevaluepair("password",password)); namevaluepairs.add(new basicnamevaluepair("phone",phone)); postrequest.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(postrequest); int statuscode = response.getstatusline().getstatuscode(); if (statuscode != 201) { throw new runtimeexception("failed http error code : " + statuscode); } }catch (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } finally{ //important: close connect httpclient.getconnectionmanager().shutdown(); } homecoming response.ok().build(); }

and got next response when phone call rest client.

status : 500 internal server error org.apache.cxf.interceptor.fault: failed http error code : 200 org.apache.cxf.service.invoker.abstractinvoker.createfault(abstractinvoker.java:162) org.apache.cxf.service.invoker.abstractinvoker.invoke(abstractinvoker.java:128) org.apache.cxf.jaxrs.jaxrsinvoker.invoke(jaxrsinvoker.java:194) org.apache.cxf.jaxrs.jaxrsinvoker.invoke(jaxrsinvoker.java:100) org.apache.cxf.interceptor.serviceinvokerinterceptor$1.run(serviceinvokerinterceptor.java:57) org.apache.cxf.interceptor.serviceinvokerinterceptor.handlemessage(serviceinvokerinterceptor.java:93) org.apache.cxf.phase.phaseinterceptorchain.dointercept(phaseinterceptorchain.java:271) org.apache.cxf.transport.chaininitiationobserver.onmessage(chaininitiationobserver.java:121) org.apache.cxf.transport.http.abstracthttpdestination.invoke(abstracthttpdestination.java:239) org.apache.cxf.transport.servlet.servletcontroller.invokedestination(servletcontroller.java:223) org.apache.cxf.transport.servlet.servletcontroller.invoke(servletcontroller.java:203) org.apache.cxf.transport.servlet.servletcontroller.invoke(servletcontroller.java:137) org.apache.cxf.transport.servlet.cxfnonspringservlet.invoke(cxfnonspringservlet.java:159) org.apache.cxf.transport.servlet.abstracthttpservlet.handlerequest(abstracthttpservlet.java:286) org.apache.cxf.transport.servlet.abstracthttpservlet.dopost(abstracthttpservlet.java:206) javax.servlet.http.httpservlet.service(httpservlet.java:755) org.apache.cxf.transport.servlet.abstracthttpservlet.service(abstracthttpservlet.java:262) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) java.lang.reflect.method.invoke(method.java:606) org.apache.catalina.security.securityutil$1.run(securityutil.java:274) org.apache.catalina.security.securityutil$1.run(securityutil.java:271) java.security.accesscontroller.doprivileged(native method) javax.security.auth.subject.doasprivileged(subject.java:536) org.apache.catalina.security.securityutil.execute(securityutil.java:306) org.apache.catalina.security.securityutil.doasprivilege(securityutil.java:166)

what reason this?

you check status using 201. can alter 200.

if (statuscode != 200) { throw new runtimeexception("failed http error code : " + statuscode); }

it's improve utilize rang instead of 1 number check http failure:

if (statuscode > 399) { throw new runtimeexception("failed http error code : " + statuscode); }

java rest wso2 jax-rs

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -