soapaction in WSDL using CXF - web-services

I am developing webservice using CXF. I use HTTP binding so according to http://www.w3.org/TR/wsdl#_soap:operation soapaction is mandatory for this type of transport.
The problem is that I want to deploy the same application for test and production server. I would like to do it without rebuilding application or keeping external WSDL files, which will add one more thing on maintenance list.
I had the same problem with location, but that one was trivial to solve. I used publishedEndpointUrl in endpoint configuration to set proper value. The value is retrieved during initialization of application from external property file, which I placed on classpath tomcat/common/classes .
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:ws.properties</value>
</list>
</property>
</bean>
<jaxws:endpoint xmlns:tns="http://example.org/ds" id="ds" implementor="org.example.Ds" wsdlLocation="wsdl/ds.wsdl" endpointName="tns:dsSOAP" serviceName="tns:Ds" address="/dsSOAP" publishedEndpointUrl="${publishedEndpointUrl}">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
I would like to achieve the same functionality for soapaction. The value for this attribute should be not relative URI. So for test it should be:
<soap:operation soapAction="https://test.example.org/dsSOAP/operation1" />
and for production
<soap:operation soapAction="https://example.org/dsSOAP/operation1" />
any idea how to achieve this?

You dont need to specify an absolute URL, you dont need either to specify a URL. "operation1" would be enough. See some official examples at http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
Linking the soap action with the environment the instance is running is not a "best practice".

Related

Configuring ActiveMQ Webconsole to redirect HTTP to HTTPS

I am using ActiveMQ Version 5.7.0 with Jetty on a RHEL 7 VM.
I have already enabled the ssl connector to access the web console via https.
Now I am trying to configure a webconsole access redirect from HTTP to HTTPS but I am really struggling with it.
In have found this guideline for "How to have Jetty redirect https to https" in this forum site: https://serverfault.com/questions/367660/how-to-have-jetty-redirect-http-to-https
I have problems to follow both steps since:
Step 1: Configure the web.xml file --> I don't know which of the following is the correct one:
apache-activemq-5.7.0/webapps/fileserver/WEB-INF/web.xml
apache-activemq-5.7.0/webapps/admin/WEB-INF/web.xml
Step 2: The instruction looks very different from the jetty.xml file of ActiveMQ where different connectors are used:
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8161" />
</bean>
<bean id="SecureConnector" class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
<property name="port" value="8162" />
<property name="keystore" value="file:${activemq.conf}/broker.ks" />
<property name="password" value="password" />
</bean>
</list>
</property>
Can anyone help me please?
Thanks very much in advance.
The admin web app is the one you want to modify. The fileserver web app is for uploading files and it was removed in 5.14.0 via AMQ-6276 due to security issues (e.g. CVE-2016-3088).
I strongly encourage you to upgrade to the latest release.

Apache ServiceMix! Request-Replay Web Service message

Hello!
I'm trying to learn some Apache Camel and Apache CXF and of course I've ran into some problems.
What I'm trying to do:
Send timed SOAP messages from ESB to some web service, wait for the reponse from the web service and process it. I'm using Apache ServiceMix!.
What I've done:
Implemented a WSDL file with two operations PingOutput (what I'm sending) and PingInput (what I want to receive from the WS).
Implemented a CXF Endpoint (http://127.0.0.1:8090/ping_ws is a WS mocked with SoapUI):
<cxf:cxfEndpoint address="http://127.0.0.1:8090/ping_ws"
id="Ping_Mocked_WS" wsdlURL="ping.wsdl">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
Implemented a Camel route:
<camelContext xmlns="http://camel.apache.org/schema/spring" streamCache="true">
<route id="ping-ws">
<from uri="timer://ping_timer?fixedRate=true&period=10000"/>
<bean ref="PingBean" method="createPingRequest" />
<to uri="cxf:bean:Ping_Mocked_WS"/>
<bean ref="PingBean" method="processPingResponse" />
</route>
</camelContext>
What I do not understand:
Why the <bean ref="PingBean" method="processPingResponse" /> gets the correct response from SoapUI (the PingOutput operation defined in WSDL)?
Is this the correct way to achieve my goal? And by this way I mean with one single route?
The codes work correctly, I might have some typos here, please do not mind them.
Thanks!
Ad 1)
Likely because the type defined in the method signature of the processPingResponse method. Camel uses bean parameter binding, and based on the type, it uses its type converter to convert to the given type.
And as the payload is a SOAP response in XML it can use JAXB to convert from XML to the type from the method signature.
To do so it uses camel-jaxb which ServiceMix comes with out of the box.
Ad2)
The route works. What it is you want to do differently?

Empty SOAP response - using JBoss 4.2, Jaxb2, Java 1.6

I am trying to deploy a spring-ws SOAP webservice in JBoss 4.2 (JDK 1.6, spring 3.0, spring-ws 2.0). I am using JAXB2 as O/X binding. Setup is fine, beans found and wired, requests can be sent and responses are generated. However, I am getting empty responses. It neither is in a SOAP envelope nor contains my simple UserDetails any content that is assembled on the server.
The correct response would be:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:UserDetails xmlns:ns2="http://a.dol.com/schemas">
<ns2:name>John</ns2:name>
<ns2:lastname>PerX</ns2:lastname>
</ns2:UserDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But I just get something like:
<Envelope>
<Header/>
<Body>
<ns2:UserDetails xmlns:ns2="http://a.dol.com/schemas"/>
</Body>
</Envelope>
After searching google, I found the following code to be added:
<beans>
<!-- Big magic hack to fix the broken SAAJ in JBoss
See http://static.springsource.org/spring-ws/sites/1.5/faq.html#saaj-jboss -->
<bean id="messageFactory">
<property name="messageFactory">
<!-- This is the Java 6 variant of this fix! Note the "internal" package missing in the spring-ws FAQ. -->
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"/>
<property>
<bean/>
</beans>
But this also doesnt help, I get the folloiwng error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageFactory' defined in ServletContext resource...
Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError...
Caused by: java.lang.IllegalArgumentException: com.sun.xml.messaging.saaj.soap.LocalStrings != com.sun.xml.internal.messaging.saaj.soap.LocalStrings
Any hints appreciated.
Updated
Updating the run.bat for JBoss with the following does fix the problem, but is this the correct way of doing it??
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.SOAPConnectionFactory=com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.SOAPFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl
Replace the spring snippet with
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"/>
</property>
</bean>
You have left out the fully qualified classname in the messageFactory bean definition.
This should work then without the startup options.
Updating the run.bat for JBoss with the following does fix the problem:
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.SOAPConnectionFactory=com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl
set JAVA_OPTS=%JAVA_OPTS% -Djavax.xml.soap.SOAPFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl

Logging in spring with method interceptors

I want to use method interceptors in spring 3 to accomplish logging in my app, so that I can trace which methods are called thru the app.
Is there a tutorial (or suggestion) on how to use method interceptors for logging in spring?
It would seem like something that has been done numerous times, but I have not been able to find much data on it.
The Spring reference has a whole chapter on Spring AOP that serves as a very detailed guide for doing what you're looking for. Try that, and if you have some more specific questions, ask.
Spring's org.springframework.aop.interceptor.CustomizableTraceInterceptor lets you achieve this out of the box.
You can customize the interceptor to your need to log argument and returned value of a method.
Example:-
<aop:config>
<aop:advisor advice-ref="loggingAdvisor"
pointcut="execution(public * com.x.y.z.AbstractCommand.*(..))" />
</aop:config>
<bean id="loggingAdvisor"
class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="loggerName" value="logger-name" />
<property name="enterMessage" value="Entering $[methodName]($[arguments])" />
<property name="exitMessage" value="Leaving $[methodName](): $[returnValue]" />
</bean>
Spring Document
Similiar SOF question answered

Securing Web Service communication with SSL using CXF

I am trying to secure communications via SSL/TLS for one of our Web Service using CXF 2.2.5.
I am wondering how to update client and server Spring configuration file to activate this feature.
I found some information on CXF's website (CXF Wiki) for the client configuration, here is the given example:
<http:conduit name="{http://apache.org/hello_world}HelloWorld.http-conduit">
<http:tlsClientParameters>
<sec:keyManagers keyPassword="password">
<sec:keyStore type="JKS" password="password"
file="src/test/java/org/apache/cxf/systest/http/resources/Morpit.jks"/>
</sec:keyManagers>
<sec:trustManagers>
<sec:keyStore type="JKS" password="password"
file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
</sec:trustManagers>
<sec:cipherSuitesFilter>
<!-- these filters ensure that a ciphersuite with
export-suitable or null encryption is used,
but exclude anonymous Diffie-Hellman key change as
this is vulnerable to man-in-the-middle attacks -->
<sec:include>.*_EXPORT_.*</sec:include>
<sec:include>.*_EXPORT1024_.*</sec:include>
<sec:include>.*_WITH_DES_.*</sec:include>
<sec:include>.*_WITH_NULL_.*</sec:include>
<sec:exclude>.*_DH_anon_.*</sec:exclude>
</sec:cipherSuitesFilter>
</http:tlsClientParameters>
<http:authorization>
<sec:UserName>Betty</sec:UserName>
<sec:Password>password</sec:Password>
</http:authorization>
<http:client AutoRedirect="true" Connection="Keep-Alive"/>
</http:conduit>
Concerning this configuration, the
Concerning the server side configuration I am unable to launch the server properly, here is the configuration I have:
<http:destination name="{urn:ihe:iti:xds-b:2007}DocumentRepository_Port_Soap12.http-destination">
</http:destination>
<httpj:engine-factory>
<httpj:engine port="9043">
<httpj:tlsServerParameters>
<sec:keyManagers keyPassword="changeit">
<sec:keyStore type="JKS" password="changeit" file="security/keystore.jks" />
</sec:keyManagers>
<sec:trustManagers>
<sec:keyStore type="JKS" password="changeit" file="security/cacerts.jks" />
</sec:trustManagers>
<sec:cipherSuitesFilter>
<!--
these filters ensure that a ciphersuite with export-suitable or null encryption is used, but exclude
anonymous Diffie-Hellman key change as this is vulnerable to man-in-the-middle attacks
-->
<sec:include>.*_EXPORT_.*</sec:include>
<sec:include>.*_EXPORT1024_.*</sec:include>
<sec:include>.*_WITH_DES_.*</sec:include>
<sec:include>.*_WITH_NULL_.*</sec:include>
<sec:exclude>.*_DH_anon_.*</sec:exclude>
</sec:cipherSuitesFilter>
<sec:clientAuthentication want="true" required="true" />
</httpj:tlsServerParameters>
</httpj:engine>
</httpj:engine-factory>
But when I run my application server (JOnas) with this configuration I have the following error message:
Line 20 in XML document from ServletContext resource [/WEB-INF/beans.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'httpj:engine-factory'.
Do you guys know how to solve this issue?
Thanks in advance,
It sounds like you are missing a namespace declaration or you have fat-fingered your XML. This is likely more of a Spring related issue than a CXF issue.
Check that the following items appear on your beans element where you declare httj:engine-factory:
<beans
...
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
...">
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
Check that the CXF Jetty Transport JAR is in your classpath at runtime.
If you add the declaration and the schema location to your context file in your IDE (at least in Eclipse with the Spring plug-ins and IDEA) you should get schema validation right in your IDE so you can easily find any mistakes you make and take advantage of auto-completion.