I could not get along with the Camel CXF component. The problem is, th WS operation that I want to call has only a String parameter which is a JSON expression.
But , with every dataFormat (MESSAGE,POJO,PAYLOAD), it gives exception.
There are classes which are generated from wsdl2java by cxf itself and I am using them to call ws.
<cxf:cxfEndpoint id="wsEndpoint" address="http://www.wssss.com" serviceClass="aa.bb.cc.WebService" serviceName="sendMessage">
<cxf:properties>
<entry key="dataFormat" value="CXF_MESSAGE"/>
<entry key="defaultOperationName" value="sendMessage"/>
<entry key="relayHeaders" value="false"/>
<entry key="wrapped" value="true"/>
<entry key="loggingFeatureEnabled" value="true"/>
<entry key="synchronous" value="true"/>
<entry key="defaultOperationNamespace" value="http://com.asdad.ns"/>
</cxf:properties>
</cxf:cxfEndpoint>
and I am using this in:
camel:to uri="cxf:bean:wsEndpoint"/>
And generated service class is:
#WebResult(name = "response", targetNamespace = "")
#RequestWrapper(localName = "sendMessage", targetNamespace = "http://com.xxx.comet.ws.notification", className = "aaa.bbb.ccc.SendMessage")
#WebMethod
#ResponseWrapper(localName = "sendMessageResponse", targetNamespace = "http://com.xxx.comet.ws.notification", className = "aaa.bbb.ccc.SendMessageResponse")
public java.lang.String sendMessage(
#WebParam(name = "request", targetNamespace = "")
java.lang.String request
);
Any help will be appreciated
Thanks
EDIT: The problem is, exchange.in body could not be bound with the service method's parameter so request is empty. There is the problem in here
INFO: Outbound Message
---------------------------
ID: 1
Address: http://www.wssss.com
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], breadcrumbId=[ID-TT08328507-61662-1416561287466-0-1], SOAPAction=[""]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body/></soap:Envelope>
--------------------------------------
Nov 21, 2014 4:45:04 AM org.apache.cxf.services.sendMessage.MessagePort.Message
INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml;charset=UTF-8
Headers: {connection=[close], Content-Length=[271], content-type=[text/xml;charset=UTF-8], Date=[Fri, 21 Nov 2014 09:15:04 GMT], Server=[Apache-Coyote/1.1]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>No binding operation info while invoking unknown method with params unknown.</faultstring></soap:Fault></soap:Body></soap:Envelope>
--------------------------------------
org.apache.cxf.binding.soap.SoapFault: No binding operation info while invoking unknown method with params unknown.
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:40)
The outbind message is an empty SOAP envelop.
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body/></soap:Envelope>
Did setup the invocation parameter rightly?
Related
I'm trying to expose a Code First Web service using Camel CXF Component. By assembling some of the available examples, I've come to the following route definition:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<bean id="productServiceImpl" class="com.demo.ws.CustomerServiceImpl" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:productServiceEndpoint" />
<bean ref="productServiceImpl" />
<!-- log input received -->
<to uri="log:output" />
</route>
</camelContext>
<cxf:cxfEndpoint id="productServiceEndpoint"
address="http://localhost:9001/productService" serviceClass="com.demo.ws.CustomerService" />
</beans>
The SEI and implementation classes I'm using are trivial:
#WebService(serviceName="customerService")
public interface CustomerService
{
public String getCustomerById(String customerId);
}
public class CustomerServiceImpl implements CustomerService
{
#Override
public String getCustomerById(String customerId)
{
System.out.println("Called with "+customerId);
return "Hello " +customerId;
}
}
When running the project, the Webservice the implementation class is called correctly, returning the String "Hello [name]", however the returned body from SOAPUI is empty:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body/>
</soap:Envelope>
Can you help me to produce the return value in the Response ?
Thank you
You should return a SOAP message :
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("responseType");
message.addTextNode("Your custom message");
return soapMessage;
You can also take a look to the camel doc examples : http://camel.apache.org/cxf-example.html
I am trying to deploy a SAML secured service in JBoss Fuse. I have consulted this link - http://cxf.apache.org/docs/jax-rs-saml.html#JAX-RSSAML-SAMLAssertionValidation.
I would like to use the Authorization header option and so have configured the server and the client as below. I am always getting the exception as "Assertion can not be validated".
Server log -->
Address: http://....
Http-Method: GET
Content-Type: /
Headers: {Accept=[/], Authorization=[SAML --encoded-string--], Cache-Control=[no-cache], connection=[keep-alive], content-type=[/], Host=[localhost:8181], Pragma=[no-cache], User-Agent=[Apache CXF 3.0.4.redhat-620123]}
2015-10-19 16:52:14,536 | WARN | p1930854886-1149 | AbstractSamlInHandler | 849 - org.apache.cxf.cxf-rt-rs-security-xml - 3.0.4.redhat-620123 | Assertion must be signed
2015-10-19 16:52:14,536 | WARN | p1930854886-1149 | AbstractSamlInHandler | 849 - org.apache.cxf.cxf-rt-rs-security-xml - 3.0.4.redhat-620123 | Assertion can not be validated
2015-10-19 16:52:14,536 | WARN | p1930854886-1149 | WebApplicationExceptionMapper | 128 - org.apache.cxf.cxf-rt-frontend-jaxrs - 3.0.4.redhat-620123 | javax.ws.rs.NotAuthorizedException: HTTP 401 Unauthorized
at org.apache.cxf.jaxrs.utils.SpecExceptions.toNotAuthorizedException(SpecExceptions.java:94)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toNotAuthorizedException(ExceptionUtils.java:134)
at org.apache.cxf.rs.security.saml.AbstractSamlInHandler.throwFault(AbstractSamlInHandler.java:243)
at org.apache.cxf.rs.security.saml.AbstractSamlInHandler.validateToken(AbstractSamlInHandler.java:181)
at org.apache.cxf.rs.security.saml.AbstractSamlInHandler.validateToken(AbstractSamlInHandler.java:115)
at org.apache.cxf.rs.security.saml.AbstractSamlInHandler.validateToken(AbstractSamlInHandler.java:98)
at org.apache.cxf.rs.security.saml.AbstractSamlBase64InHandler.handleToken(AbstractSamlBase64InHandler.java:53)
at org.apache.cxf.rs.security.saml.SamlHeaderInHandler.filter(SamlHeaderInHandler.java:52)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.runContainerRequestFilters(JAXRSUtils.java:1647)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:106)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
Server -->
<jaxrs:server id="service111" address="/saml/test">
<jaxrs:serviceBeans>
<ref component-id="serviceBean"/>
</jaxrs:serviceBeans>
<jaxrs:features>
<bean class="org.apache.cxf.jaxrs.swagger.SwaggerFeature"/>
</jaxrs:features>
<jaxrs:providers>
<ref component-id="jaxbProvider" />
<ref component-id="jsonProvider" />
<!-- SAML -->
<ref component-id="samlHandler"/>
</jaxrs:providers>
<!-- SAML -->
<jaxrs:properties>
<entry key="ws-security.signature.properties" value="alice.properties"/>
</jaxrs:properties>
</jaxrs:server>
<!-- SAML -->
<!-- Authorization Header -->
<bean id="samlHandler" class="org.apache.cxf.rs.security.saml.SamlHeaderInHandler"/>
Client code -->
public class JavaTestAPI {
/*
* SAML
*/
private WebClient createWebClient(String address) {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
Map<String, Object> properties = new HashMap<String, Object>();
/*properties.put("ws-security.callback-handler", "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
properties.put("ws-security.saml-callback-handler", "org.apache.cxf.systest.jaxrs.security.saml.SamlCallbackHandler");
*/
properties.put("ws-security.callback-handler", "org.rest.test.saml.KeystorePasswordCallback");
properties.put("ws-security.saml-callback-handler", "org.rest.test.saml.SamlCallbackHandler");
properties.put("ws-security.signature.username", "alice");
properties.put("ws-security.signature.properties", "alice.properties");
properties.put("ws-security.self-sign-saml-assertion", "true");
bean.setProperties(properties);
bean.getOutInterceptors().add(new SamlHeaderOutInterceptor());
return bean.createWebClient();
}
public static void main(String[] args) {
JavaTestSolrAPI test = new JavaTestAPI();
String address = "http://localhost:8181/cxf/saml/test/1.0.0?codes=usa,ger&format=json";
System.out.println("before createWebClient..");
WebClient wc = test.createWebClient(address);
System.out.println("wc=" + wc);
Response resp = wc.get();
System.out.println("after response=" + resp.getStatus());
System.out.println("response=" + resp.readEntity(String.class));
}
}
I'm not sure if it's the root of your problem, but it appears that the assertion statement you're getting back isn't signed, when it should be.
I need to set the use-x-forwarded-headers Http header in camel-cxf like the below and make it as an OSGi bundle to be deployed in Karaf.
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>use-x-forwarded-headers</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I don't want to package this as a WAR, instead i want to make it an OSGi bundle.
Hence, i created a class which extends CXFNonSpringServlet as the code below and set the init-params,
public class XForwadedServlet extends CXFNonSpringServlet {
#Override
protected void loadBus(ServletConfig sc) {
sc.getServletContext().setInitParameter("use-x-forwarded-headers",
"true");
super.loadBus(sc);
Bus bus = getBus();
BusFactory.setDefaultBus(bus);
// createFactoryBean();
}
#Override
public void init(ServletConfig sc) throws ServletException {
sc.getServletContext().setInitParameter("use-x-forwarded-headers",
"true");
super.init(sc);
}
And here's my camel route,
<cxf:cxfEndpoint id="serviceEndpoint"
address="http://localhost:8123/cxf/testCxfRedirect"
loggingFeatureEnabled="true" serviceClass="com.redhat.HelloServiceImpl">
</cxf:cxfEndpoint>
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:serviceEndpoint"/>
<log message="${body}" loggingLevel="INFO"/>
<bean ref="clientAddress" method="getClientAddress"/>
</route>
</camelContext>
<bean id="destinationRegistry" class="org.apache.cxf.transport.http.DestinationRegistryImpl">
</bean>
<bean id="osgiServlet" class="com.redhat.XForwadedServlet">
<constructor-arg ref="destinationRegistry"></constructor-arg>
<constructor-arg value="true"></constructor-arg>
</bean>
Through soapui, i set the X-Forwarded-For header as below,
Address: http://localhost:8123/cxf/testCxfRedirect
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], SOAPAction=[""], X-Forwarded-For=[http://google.com]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:sayHello xmlns:ns1="http://redhat.com/"><arg0 xmlns="http://redhat.com/">Test</arg0></ns1:sayHello></soap:Body></soap:Envelope>
--------------------------------------
How can i register the CXFNonSpringServlet in OSGi Blueprint container with setting that init-params ?
Is there a way to do this in OSGi ?
This can be achieved by using the pax-web-extender support in Fuse, Camel.
However the packaging will need to be WAR.
Here's the reference from Karaf:
https://ops4j1.jira.com/wiki/display/ops4j/Pax+Web+Extender+-+War+-+Examples
Here's a reference implementation from the Camel Committers:
https://github.com/apache/camel/tree/master/examples/camel-example-reportincident
Hope it helps.
I am using the below AngularJS client code to perform a HTTP post request with JSON formatted payload to the jersey rest service
patientMgmtModule.controller('NewPatientCtrl',
function NewPatientCtrl($scope, $http)
{
$scope.addPatient = function (){
var patientJSON = angular.toJson($scope.Patient);
console.log("Patient (JSON) is ============> " + patientJSON);
$http({
method: 'POST',
data: $scope.Patient,
url:'/ManagePatient/AddPatient',
headers: {'Content-Type':'application/x-www-form-urlencoded;application/json;'}
});
};
}
);
I have the following maven dependencies for Jersey:
<dependency>
<groupId>org.glassfish.jersey.archetypes</groupId>
<artifactId>jersey-quickstart-webapp</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.0</version>
</dependency>
On the Server Side, I have
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.hms.app.ui.beans.Patient;
#Path("/ManagePatient")
public class PatientController {
#POST
#Path("/AddPatient")
#Consumes({MediaType.APPLICATION_JSON})
public String addPatient(Patient patient) {
System.out.println("Sarat's servlet called" );
//patient.toConsole();
System.out.println("Done Calling Patient To Console");
return "Done Calling Patient To Console";
}
}
When I submit the form on the client side, I see the below error in the chrome console -
POST http://localhost:8080/HMS_Web/services/ManagePatient/AddPatient 500 (Internal Server Error) angular.min.js:99
and on the server end, I see (high level detail 1):
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/HMS_Web] threw exception
org.glassfish.jersey.message.internal.HeaderValueException: Unable to parse "Content-Type" header value: "application/x-www-form-urlencoded;application/json;"
and the last stack trace has this:
Caused by: java.text.ParseException: Expected separator '=' instead of '/'
Detailed stack trace: (
Aug 01, 2013 9:28:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/HMS_Web] threw exception
org.glassfish.jersey.message.internal.HeaderValueException: Unable to parse "Content-Type" header value: "application/x-www-form-urlencoded;application/json;"
at org.glassfish.jersey.message.internal.InboundMessageContext.exception(InboundMessageContext.java:318)
at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:313)
at org.glassfish.jersey.message.internal.InboundMessageContext.getMediaType(InboundMessageContext.java:427)
at org.glassfish.jersey.servlet.WebComponent.filterFormParameters(WebComponent.java:482)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:303)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Error parsing media type 'application/x-www-form-urlencoded;application/json;'
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:433)
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:427)
at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:311)
... 22 more
Caused by: java.lang.IllegalArgumentException: Error parsing media type 'application/x-www-form-urlencoded;application/json;'
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:89)
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:59)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:431)
... 24 more
Caused by: java.text.ParseException: Expected separator '=' instead of '/'
at org.glassfish.jersey.message.internal.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:115)
at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:261)
at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:242)
at org.glassfish.jersey.message.internal.MediaTypeProvider.valueOf(MediaTypeProvider.java:107)
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:87)
... 27 more
Aug 01, 2013 9:29:00 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/HMS_Web] threw exception
org.glassfish.jersey.message.internal.HeaderValueException: Unable to parse "Content-Type" header value: "application/x-www-form-urlencoded;application/json;"
at org.glassfish.jersey.message.internal.InboundMessageContext.exception(InboundMessageContext.java:318)
at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:313)
at org.glassfish.jersey.message.internal.InboundMessageContext.getMediaType(InboundMessageContext.java:427)
at org.glassfish.jersey.servlet.WebComponent.filterFormParameters(WebComponent.java:482)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:303)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Error parsing media type 'application/x-www-form-urlencoded;application/json;'
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:433)
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:427)
at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:311)
... 22 more
Caused by: java.lang.IllegalArgumentException: Error parsing media type 'application/x-www-form-urlencoded;application/json;'
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:89)
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:59)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:431)
... 24 more
Caused by: java.text.ParseException: Expected separator '=' instead of '/'
at org.glassfish.jersey.message.internal.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:115)
at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:261)
at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:242)
at org.glassfish.jersey.message.internal.MediaTypeProvider.valueOf(MediaTypeProvider.java:107)
at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:87)
... 27 more
After implementing LoggingFilter - I see that the server is responding with HTTP 415.
Aug 04, 2013 10:28:25 AM org.glassfish.jersey.filter.LoggingFilter log
INFO: 2 * LoggingFilter - Request received on thread tomcat-http--11
2 > POST http://localhost:8080/HMS_Web/services/ManagePatient/AddPatient
2 > host: localhost:8080
2 > connection: keep-alive
2 > content-length: 341
2 > accept: application/json, text/plain, */*
2 > origin: http://localhost:8080
2 > x-requested-with: XMLHttpRequest
2 > user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
2 > content-type: application/json
2 > dnt: 1
2 > referer: http://localhost:8080/HMS_Web/views/Landing.html
2 > accept-encoding: gzip,deflate,sdch
2 > accept-language: en-US,en;q=0.8
Aug 04, 2013 10:28:25 AM org.glassfish.jersey.filter.LoggingFilter log
INFO: 2 * LoggingFilter - Response received on thread tomcat-http--11
2 < 415
Your Content-Type header is invalid (see spec 14.17 Content-Type). Based on you JAX-RS resource you should use application/json as Content-Type (without application/x-www-form-urlencoded):
$http({
method: 'POST',
data: $scope.Patient,
url:'/ManagePatient/AddPatient',
headers: {'Content-Type':'application/json'}
});
EDIT 1:
If you want to see requests that are coming to your server you can register LoggingFilter and it will show you some useful information. You can turn it on in:
web.xml (add it to the JAX-RS servlet definition):
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
Application extension:
public class MyApplication extends Application {
#Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>() {{
// Add your resources.
add(HelloWorldResource.class);
// Add LoggingFilter.
add(LoggingFilter.class);
}};
}
}
ResourceConfig instance (demonstrating also outputting the entity here):
public class MyApplication extends ResourceConfig {
public MyApplication() {
// Resources - add your package name here to enable package scanning.
packages(...);
// Enable LoggingFilter & output entity.
registerInstances(new LoggingFilter(Logger.getLogger(MyApplication.class.getName()), true));
}
}
EDIT 2:
Jersey 2.x does not support application/json media type out of the box - you need to add one of the JSON modules to your classpath (see JSON section in users guide), for example:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.0</version>
</dependency>
i was creating cxf/camel webservice and i've created for test code like this:
#GET
#Path("/user")
#ProduceMime({ "application/json" })
public String user(#FormParam("token") String token) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure(){
from("direct:start").to("http://google.com");
}
});
context.start();
return token;
}
}
Then i've compiled it and copied do FUSE ESB deploy folder. My webservice was installed, but when i opened URL with my webservice i got 500 response:
org.apache.cxf.interceptor.Fault: Failed to create route route17 at: >>> To[http://google.com] <<< in route: Route[[From[direct:start]] -> [To[http://google.com]]] because of Failed to resolve endpoint: http://google.com due to: No component found with scheme: http
Caused by:
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Failed to create route route17 at: >>> To[http://google.com] <<< in route: Route[[From[direct:start]] -> [To[http://google.com]]] because of Failed to resolve endpoint: http://google.com due to: No component found with scheme: http
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:108)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:323)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:209)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:152)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:480)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:116)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:72)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:438)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:905)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:561)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:43)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:538)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:43)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
at java.lang.Thread.run(Thread.java:680)
additionally i have imported:
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.component.http.*;
import org.apache.camel.component.http.helper.*;
on ESB i have turned on camel-http
what is wrong?
--------------
So i this what i wrote is wrong, is this code below should works right?
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
<bean id="cxfSSO" class="com.esb.cxf.SSO" />
<jaxrs:server id="sso" address="/ssocamel2">
<jaxrs:serviceBeans>
<ref bean="cxfSSO" />
</jaxrs:serviceBeans>
</jaxrs:server>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<endpoint id="endpointURL" uri="http://localhost:8080/SSO/?token=test"/>
<route>
<from uri="direct:start"/>
<to uri="callRealWebService"/>
</route>
</camelContext>
</beans>
You need to install the camel-http feature. From the Fuse ESB console you can type:
features:install camel-http
And then after that you can install/start your bundle.
And as Ben says, what you are doing inside the rest service is totally wrong. You should setup Camel route once. If you want to call a http endpoint from Java code using Camel, then you do not need a route, but you can use a ProducerTemplate. See the Camel docs for more details.
couple of things, "No component found with scheme: http" means that you are missing the camel-http dependency in your bundle
next, you should setup your Camel context/routes once...not in a method call like this.