I have a CXF service (2.5.2) which consumes JSON object and produces JSON object like below
#POST
#Produces({"application/json"})
#Consumes({"application/json"})
public AResponseObject register(#PathParam("param1") String param1, User user) {
//
}
WADL generated by CXF for above service is as following:
<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<script id="tinyhippos-injected"/>
<grammars/>
<resources base="http://host/...">
<resource path="/register/{param1}">
<param name="param1" style="template" type="xs:string"/>
<method name="POST" id="register">
<request>
<representation mediaType="application/json"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
</resources>
</application>
Above WADL file:-
doesn’t give any details for what User object is in grammars section
resource doesn’t specify that method requires a User object in request
payload
How do I add these missing things to the WADL file?
Thanks.
You need to add the cxf WadlGenerator as a provider in your Blueprint file:
<bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
</bean>
<jaxrs:server id="someRestService" address="/my/endpoint">
<jaxrs:serviceBeans>
<ref component-id="someRestServiceBean" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref component-id="wadlGenerator" />
<ref component-id="jsonProvider" />
</jaxrs:providers>
</jaxrs:server>
Related
We are using ServiceMix 7.0.0.M3 and use the CXF WADL generator.
Now the generated WADL does not seem to have a 'id' attribute in the resource>method tags. For example, the 4th line in the following WADL does not have an 'id' attribute.
<resources base="http://localhost:8181/api/rest/box">
<resource path="/">
<resource path="boxes">
<method name="GET">
<request>
<param name="language" style="header" type="xs:string"/>
<param name="includeInactive" style="query" type="xs:boolean"/>
</request>
<response>
<representation mediaType="application/json;charset=utf-8" element="prefix1:BoxRestResponse"/>
</response>
</method>
</resource>
If I would have the WADL generated with Jersey, I would get an 'id' property, containing the name of the corresponding Java method.
<resources base="http://localhost:8181/api/rest/box">
<resource path="/">
<resource path="boxes">
<method name="GET" id="getBoxes">
<request>
<param name="language" style="header" type="xs:string"/>
<param name="includeInactive" style="query" type="xs:boolean"/>
</request>
<response>
<representation mediaType="application/json;charset=utf-8" element="prefix1:BoxRestResponse"/>
</response>
</method>
</resource>
One of our frontend development tools expects the 'id' attribute to be present.
Is it possible to configure the CXF WADL generator to include the method id attribute?
I found it. The id's are generated when adding the WadlGenerator configuration property 'addResourceAndMethodIds' to the CXF Blueprint file:
<bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<!-- properties: Method Summaries # https://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.html -->
<property name="linkJsonToXmlSchema" value="true" />
<property name="useJaxbContextForQnames" value="true" />
<property name="addResourceAndMethodIds" value="true" />
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<!-- Defined the real JAXRS back end service -->
<jaxrs:server id="restService"
address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="customerService"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>
<bean id="customerService" class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService" />
<!-- Defined the server endpoint to create the cxf-rs consumer -->
<cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsServer>
<!-- Defined the client endpoint to create the cxf-rs consumer -->
<cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsClient>
<!-- The camel route context -->
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- Just need to ignoreDeleteMethodMessageBody -->
<from uri="cxfrs://bean://rsServer"/>
<to uri="log:body?level=INFO"/>
<to uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true"/>
</route>
</camelContext>
</beans>
In the Camel Docs they say that cxf:rsServer is a REST Consumer where as cxf:rsClient is a REST producer but the code seems to do vice-versa.
Also i want to understand the difference between Jaxrs tag and cxf:rsserver and cxf:rsclient tags.
jaxrs:server : create a basic endpoint service.
cxf:rsServer : Is a camel component to create REST endpoint. It will turn a request into a normal Java object.
cxf:rsClient : Do the opposite of rsServer, it turn a java object to a REST request.
<camelContext>
<route>
<from uri="cxfrs://bean://rsServer" />
<to uri="log:body?level=INFO" />
<to uri="cxfrs://bean://..=true" />
</route>
</camelContext>
If we take a look to the code example, we see that this is a proxy. We received a REST request, we log it and then forward it.
<cxf:rsServer id="rsServer" address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsServer>
<cxf:rsClient id="rsClient" address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
loggingFeatureEnabled="true" skipFaultLogging="true">
<cxf:providers>
<ref bean="jsonProvider"/>
</cxf:providers>
</cxf:rsClient>
Theses tags is for configure your cxf component outside from the camel-route.
Hope this help.
Have implemented a CXF client using WSDL which already has WS-SecurityPolicy defined within it . It is working fine otherwise and is used by a web application heavily.
But we observed in perf env that intermittently multiple wsse:Security header is getting added to the SOAP header resulting in failure. It is intermittent and not able to reproduce it in dev environment.
Here is the client configuration:
<jaxws:client
xmlns:tns="http://ws.soa.com/service/XYZ/XYZService/"
name="XYZPort" address="${XYZService.endPoint}"
serviceClass="com.soa.ws.service.XYZ.XYZService.XYZPortType"
serviceName="tns:XYZService">
<jaxws:properties>
<entry key="ws-security.username" value="${XYZService.auth.username}" />
<entry key="ws-security.callback-handler" value-ref="XYZServicePasswordCallback" />
</jaxws:properties>
<jaxws:inInterceptors>
<ref bean="logInBound" />
<ref bean="XYZServiceSOAPResponseInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="logOutBound" />
<ref bean="XYZServiceSOAPRequestInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
<bean id="XYZServicePasswordCallback" class="com.services.client.XYZ.XYZServiceClientPasswordCallback" >
<property name="username" value="${XYZService.auth.username}" />
<property name="password" value="${XYZService.auth.password}" />
<!-- Decrypt key defined in keyfile.properties -->
<property name="secretKey" value="${key}" />
</bean>
Here is the Intermitttent issue. Security header added twice
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis- open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-33466425961" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XYZPwd</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-33466425962" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XYZPwd</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
I have a web application providing rest full service and another standalone (jar) application doing soap request response (using camel)
Can someone give me pointers to me for how to integrate the two applications
Specifically around how to kick camel routes when war file is deployed in tomcat, and how to re-run the routes when a specific HTTP request arrives.
I am using camel DSL (xml) and spring.
UPDATE 1:
I have followed this
Checked that web.xml has following lines:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mycompany.server.Binder</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Created a /WEB-INF/applicationContext.xml file and put all my routes and beans in it (btw I have beans.xml file as well in src/main/resources which is getting read by spring).
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
">
<!-- Camel applicationContext -->
<!-- this import needed to bring in CXF classes -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:${env}/my.properties" />
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:${env}/my.properties</value>
</list>
</property>
</bean>
<camel:camelContext id="camelContext">
<camel:contextScan/>
<camel:template id="serviceConsumerTemplate" defaultEndpoint="direct:start" />
<camel:threadPoolProfile defaultProfile="true" id="defaultThreadPool" poolSize="10" maxPoolSize="15" />
<camel:route id="serviceGetAccount">
<camel:from uri="timer://kickoff?repeatCount=1"/>
<camel:to uri="bean:serviceGetAccountProcessor" />
<camel:to uri="bean:serviceRequestHeaderCreator" />
<camel:to uri="cxf:bean:serviceGetAccountEndpoint?dataFormat=POJO" />
<camel:to uri="bean:serviceGetAccountResponseProcessor" />
</camel:route>
</camel:camelContext>
<bean id="serviceRequestHeaderCreator" class="com.mycompany.service.soap.SOARequestHeaderCreator">
<property name="serviceName" value="service" />
<property name="spnValue" value="${nj.spn}" />
<property name="securityTokenEnabled" value="true" />
<property name="sendingApplication" value="NJ SERVICE" />
<property name="serviceVersion" value="3.0.2" />
<property name="sendingHost" ref="localHostName"/>
</bean>
<cxf:cxfEndpoint id="serviceGetAccountEndpoint"
address="${request.endpoint}/serviceAccountRequestResponsePT"
endpointName="s:serviceAccountRequestResponsePort"
serviceName="s:serviceAccountRequestResponseHTTP"
xmlns:s="http://soa.mycompany.com/services/service/wsdl/v3"
serviceClass="com.mycompany.services.service.wsdl.v3.serviceAccountRequestResponsePT"
loggingFeatureEnabled="true">
</cxf:cxfEndpoint>
<bean id="serviceGetAccountProcessor" class="com.mycompany.service.serviceGetAccountProcessor"/>
<bean id="serviceGetAccountResponseProcessor" class="com.mycompany.service.serviceGetAccountResponseProcessor"/>
</beans>
Up the logging level of log4j.logger.org.apache.camel=DEBUG
However do not see any camel log lines of routes starting.
Update 2:
I was not doing mvn clean generate-sources.
Once I started doing mvn clean and rebuilding the war file, camel kicked in.
Seems your spring context does not really fire. Make sure it is!
There should be some Spring info log events telling you about this.
Try adding this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
Below is my setup for the new Spring 3 annotation based controller:
// dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<!-- Enables plain controllers -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="ignoreAcceptHeader" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
</bean>
<!-- Entity Property binding for webBindingInitializer -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.opevel.web.BindingInitializer" />
</property>
</bean>
<context:component-scan base-package="org.opevel.web"/>
</beans>
// web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
<url-pattern>/auth</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
// Spring controller
package org.opevel.web;
#Controller
public class LoginGoogleController {
private static final Logger log = Logger.getLogger(LoginGoogleController.class.getName());
public LoginGoogleController() {
log.info("constructing LoginGoogleController");
}
#RequestMapping(value="/auth", method=RequestMethod.GET)
public String doGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
return "redirect:index";
}
}
When I navigate to /auth, I get a 404. When I try to register the bean in the applicationContext like this:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/auth">GoogleLoginService</prop>
</props>
</property>
<bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" />
I get a BeanException stating that the bean is already registered at /logingoogle through ControllerClassNamehandlerMapping. I am using Spring 3.0.2 on Google App Engine.
Will appreciate some help.
I was able to fix this my removing both the ControllerClassNameHandlerMapping and SimpleUrlHandlerMapping beans from the application context file.
Regards y'all
That error is telling you that you don't need <bean id="GoogleLoginService" class="org.opevel.web.LoginGoogleController" /> in your applicationContext. Also you don't need <bean id="urlMapping">
#Controller creates a bean for you and #RequestMapping creates the URL mapping.