Missing method id attribute in generated WADL with ServiceMix 7 M3 and CXF - cxf

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>

Related

Log4j generate different files with the same content

I'm working with a Java application that integrates log4j. For a new development I would need that instead of generating a file I will generate two, one per country that is accessed from the application web. Both would have the same log records that are found throughout my application.
I configured the configuration using an .xml file:
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="jeveris: %d{dd MMM yyyy HH:mm:ss,SSS} %-5p %c - %m%n" />
</layout>
</appender>
<appender name="One-Console" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="Console.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="2MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p %c - %m%n" />
</layout>
</appender>
<category name="com.example.one.web">
<level value="debug" />
<appender-ref ref="One-Console" />
</category>
<root>
<appender-ref ref="console" />
<level value="debug" />
</root>
</log4j:configuration>
Could someone guide me, tell me if it is possible or help me find the solution?
Thank you.
If you want 2+ log files that will print the same content, then you could fine 2 different files in your tag like so:
<configuration status="OFF">
<Properties>
<Property name="log-path">/your/file/path/</Property>
<Property name="log-country-name1">Country1</Property>
<Property name="log-country-name2">Country2</Property>
<!-- more if necessary -->
<Property name="log-pattern">%d{ISO8601} %-5p [%t|%c{1}] %m\n</Property>
<Property name="rollover-strategy-max">5</Property>
<Property name="rolling-size-based">10 MB</Property>
</Properties>
<appenders>
<!--uncomment following if want to print to console as well -->
<!-- <Console name="Console" target="SYSTEM_OUT">
<PatternLayout>
<pattern>${log-pattern}</pattern>
</PatternLayout>
</Console> -->
<RollingFile name="INFO" fileName="${log-path}/${log-country-name1}-logger.log" filePattern="${log-path}/${log-project-name}-debug-%d-%i.log.zip">
<PatternLayout>
<pattern>${log-pattern}</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="${rolling-size-based}" />
</Policies>
<DefaultRolloverStrategy max="${rollover-strategy-max}" />
</RollingFile>
<RollingFile name="INFO" fileName="${log-path}/UpdaterLocal-logger.log" filePattern="${log-path}/${log-country-name2}-debug-%d-%i.log.zip">
<PatternLayout>
<pattern>${log-pattern}</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="${rolling-size-based}" />
</Policies>
<DefaultRolloverStrategy max="${rollover-strategy-max}" />
</RollingFile>
</appenders>
<Loggers>
<logger name="io.switchfour" level="trace" additivity="false">
<AppenderRef ref="INFO" level="info" />
</logger>
</Loggers>
The above will create /your/file/path/Country1-logger.log and /your/file/path/Country2-logger.log and will write all entries that are INFO or higher to both files. Your log file should be identical.

CXF WADL missing details for complex objects

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>

Multiple <wsse:Security> header getting added to SOAP Header : CXF Client Implementation

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>

Camel: using property placeholders for boolean attribute in CXF endpoint configuration

I like to use a property placeholder for a Boolean attribute in my CXF endpoint definition.I've read the doc about the placeholder prefix in http://camel.apache.org/using-propertyplaceholder.html but ik cannot figure out how to apply them in my endpoint configuration. String placeholders work fine. In the example below I use Boolean attribute ${ws-logging}, and the XML won't validate. How can I use a property placeholder for a Boolean attribute in a CXF endpoint configuration?
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:prop="http://camel.apache.org/schema/placeholder"
xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<property-placeholder persistent-id="test.config" id="test.config.placeholder" xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0">
<default-properties>
<property name="ws-logging" value="true"/>
</default-properties>
</property-placeholder>
<camel-cxf:cxfEndpoint id="update"
address="http://someaddress"
endpointName="ssp:someendpoint"
serviceName="ssp:someservice"
wsdlURL="http://someaddress/wsdl?targetURI=sometargeturi"
xmlns:ssp="somenamespace"
loggingFeatureEnabled="${ws-logging}">
<camel-cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</camel-cxf:properties>
</camel-cxf:cxfEndpoint>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="timerToLog">
<from uri="timer:foo?period=5000"/>
<to uri="mock:result"/>
</route>
</camelContext>
</blueprint>
I believe you're missing a schema reference and namespace: blueprint-cm. Try adding it like the example below.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel-cxf="http://camel.apache.org/schema/cxf"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xsi:schemaLocation="http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder persistent-id="com.example">
<cm:default-properties>
<property name="ws-logging" value="true"/>
</cm:default-properties>
</cm:property-placeholder>
</blueprint>

Camel integration with existing web application

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>

Resources