WSO2 problem during Proxy Service for SOAP to REST transformation - java

I'm new on WSO2 and for a huge project we are using the EI 6.1.1.
One of our goals is to create some REST services that must substitutes some legacy SOAP services: for do that, we are developing Spring Boot REST and our idea is to expose these one in a SOAP way, with same WSDL of the legacy service.
We are creating a Proxy Service on WSO2 and we are able to call the rest service in backend, but, even if the REST logging show us that everything goes fine, the SOAP call never send back response, and "die" with a read timeout.
How can we fix that? I'll post you the proxyService configuration:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="VerificaAmbitiSET_SOAP_AWS"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<filter xmlns:ver="http://XXXXXX.XXXXXX.XXXXXX"
xpath="//ver:getAmbitiSet">
<then>
<property expression="//ver:getAmbitiSet/ver:codiceFiscale"
name="REST_URL_POSTFIX"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="GET"/>
</then>
<else/>
</filter>
<header name="Accept" scope="transport" value="*/*"/>
<send>
<endpoint>
<address format="rest"
uri="http://localhost:8280/services/A_SERVICE/ambitiSet"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL key="conf:/wsdl/A_WSDL.wsdl"/>
<description/>
</proxy>
and this is the REST controller sign:
#GetMapping(value = "/ambitiSet/{codiceFiscale}")
public List<Ambito> getAmbitiSET(#PathVariable("codiceFiscale") String codiceFiscale)
Finally, my SOAP request looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ver="http://XXXX.XXXXX.XXXXXX">
<soapenv:Header/>
<soapenv:Body>
<ver:getAmbitiSet>
<ver:codiceFiscale>XXZXZXZXZ</ver:codiceFiscale>
</ver:getAmbitiSet>
</soapenv:Body>
</soapenv:Envelope>
Greeting.

You can test where the response is getting dropped via enabling wire logs. Please follow the blog https://medium.com/#tharika/how-to-read-and-understand-wire-logs-in-wso2-products-c384af0b8ea5

Related

Cxf Endpoint getting up with start of camel context. How I can avoid this?

I am using CXF endpoint for soap web service. And when my camel context starts it check whether web service is running or not. I want to change it like when my route call the CXF endpoint at that time it should check whether my service is running or not?
Any suggestions for fulfilling my requirement?
CXF Endpoint:
<cxf:cxfEndpoint id="accountBalanceServiceEndpoint"
address="{{wsdlUrlTest}}"
wsdlURL="{{wsdlUrlTest}}?wsdl"
serviceName="s:AccountBalanceService"
endpointName="s:AccountBalancePort"
xmlns:s="http://soap.test.pqr.abc.com/">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE"/>
</cxf:properties>
</cxf:cxfEndpoint>
Route:
<route id="SoapService" startupOrder="40">
<from uri="direct:SoapService" />
<setHeader headerName="operationNamespace">
<constant>http://soap.test.pqr.abc.com/</constant>
</setHeader>
<setHeader headerName="operationName">
<constant>getContacts</constant>
</setHeader>
<setBody>
<simple>
<![CDATA[
<soapenv:Envelope
xmlns:q0="http://soap.test.pqr.abc.com/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
<soapenv:Body>
<q0:getContacts>
<arg0>
<custId>12345</custId>
</arg0>
</q0:getContacts>
</soapenv:Body>
</soapenv:Envelope>
]]>
</simple>
</setBody>
<to uri="cxf:bean:accountBalanceServiceEndpoint?defaultOperationName=getContacts" />
</route>
CXF doesn't check the availability of the service you are invoking when the route is starting up. CXF will only establish Http(s)Connection when the request is made. I am suspecting you are running into issues with discovering WSDL from the endpoint of service you are invoking in which case, it may establish a connection to download the WSDL and schemas when CXFEndpoint is instantiated.
Downloading the WSDL and schemas first and load it from file offline instead of using serviceUrl?WSDL may help you.

getting an WS-security error while trying to send SOAP request toweb service

Here is my SOAP request which I sent using soap UI and I'm getting an error saying that "Message does not conform to configured policy"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:csw="http://www.cargospot.com/crystal/cswebservice">
<soapenv:Header>
<xwss:SecurityConfiguration dumpMessages="false" xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:RequireUsernameToken passwordDigestRequired="true" nonceRequired="true"/>
<xwss:UsernameToken name="somename" password="somepassword" useNonce="true" digestPassword="true"/>
</xwss:SecurityConfiguration>
</soapenv:Header>
<soapenv:Body>
<csw:cargoImpMessageRequest>
<csw:content>test</csw:content>
</csw:cargoImpMessageRequest>
</soapenv:Body>
</soapenv:Envelope>
I'm getting below response,
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">com.sun.xml.wss.XWSSecurityException: Message does not conform to configured policy [ AuthenticationTokenPolicy(S) ]: No Security Header found; nested exception is com.sun.xml.wss.XWSSecurityException: com.sun.xml.wss.XWSSecurityException: Message does not conform to configured policy [ AuthenticationTokenPolicy(S) ]: No Security Header found</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Below is the Web service security configuration ,
<!-- Web Service Security Configuration -->
<bean id="xwssSecurityInterceptor" class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">
<description>
This interceptor validates incoming messages according to the policy defined in 'securityPolicy.xml'.
The policy defines that all incoming requests must have a UsernameToken with a password digest in it.
The actual authentication is performed by the Acegi callback handler.
</description>
<property name="policyConfiguration" value="/WEB-INF/securityPolicy.xml"/>
<property name="callbackHandler" ref="digestPasswordCallback" />
</bean>
<bean id="digestPasswordCallback" class="org.springframework.ws.soap.security.xwss.callback.acegi.AcegiDigestPasswordValidationCallbackHandler">
<property name="userDetailsService" ref="userDetailsService"/>
</bean>
<bean id="userDetailsService" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
<property name="userProperties">
<bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="/WEB-INF/csws-users.properties" />
</bean>
</property>
</bean>
below is the security policy
<xwss:SecurityConfiguration dumpMessages="false" xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:RequireUsernameToken passwordDigestRequired="true" nonceRequired="true"/>
<xwss:UsernameToken name="somename" password="somepassword" useNonce="true" digestPassword="true"/>-->
</xwss:SecurityConfiguration>
I'm not sure what I have missed in SOAP request, kindly help me to find the issue with soap request.
Thanks
Try adding the following header in your SOAP request:
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" wsse:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>userName</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>

Mule Enrichment: enrich xml payload with http endpoint response

I'm new to mule and working on a POC. I want to enrich the payload(target.xml) by calling an http endpoint which returns xml as response (source.xml) .
<flow name="mule-configFlow" doc:name="mule-configFlow">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="QUEUE1"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
<enricher doc:name="Message Enricher" target="#[xpath:Customer/OfficeId]">
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8095" path="myservice/v1/" method="GET" doc:name="HTTP">
<expression-transformer evaluator="xpath" expression="Response/OffId" />
</http:outbound-endpoint>
</enricher>
<jms:outbound-endpoint queue="QUEUE2" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
I've verified and http endpoint works fine but I'm getting the below error
Expression Evaluator "xpath" with expression "Response/OffId" returned null but a value was required
Am i configuring the source and target expression correctly ?
Incoming Message payload (target.xml):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.xyz.com/abc/v1">
<ActionType>ACCOUNT_ADDED</ActionType>
<OfficeId></OfficeId>
<MemberId></MemberId>
</Customer>
Source for enrichment (source.xml):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response xmlns="http://www.xyz.com/abc/v1">
<OffId></OffId>
<MemId></MemId>
</Response>
There's a couple of issues here:
your expression transformer will not work inside the outbound endpoint
your xpath expression will not work due to the xmlns ref in the xml
you can not transform an xml string with an enhancer
To make this work, put the outbound endpoint and the expression transporter inside a process-chain, use an xpath expression that either handles namespaces or ignores them, and transform your initial xml string payload to something else, for example DOM, that you can manipulate.
Something like this should work:
<mulexml:xml-to-dom-transformer returnClass="org.dom4j.Document"/>
<enricher source="#[payload]" target="#[payload.rootElement.element('OfficeId').text]">
<processor-chain>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8095" path="myservice/v1/" method="GET"/>
<expression-transformer evaluator="xpath" expression="//*[local-name()='OffId']" />
</processor-chain>
</enricher>

Security Policy Error Calling Java Web Service From .Net

I am trying to call a Java web service, over Http not Https, using .Net. The only hint I got from the web service team is to pass the credential either in SOAP message or in the endpoint settings.
I have created a simple console application and added a service reference to the web service. The following is the generated binding (I see that there is warning about unrecognized policy but cannot figure what it means or whether it is relevant or not):
<customBinding>
<binding name="CurrencyInformationServiceSoapBinding">
<!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://www.openuri.org/': -->
<!-- <wsdl:binding name='CurrencyInformationServiceSoapBinding'> -->
<!-- <ns1:SupportingTokens xmlns:ns1="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512">..</ns1:SupportingTokens> -->
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap11" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<!--<security authenticationMode="UserNameOverTransport" allowInsecureTransport="true"/>-->
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
Here are my trials:
Trail #1:
-----------
Using the following code:
CurrencyInformationServiceClient client = new CurrencyInformationServiceClient();
foreignCurrencyDTO[] results = client.getAllForeignCurrencies();
or supplying the credentials in Windows property
CurrencyInformationServiceClient client = new CurrencyInformationServiceClient();
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("crmuser", "welcome1");
foreignCurrencyDTO[] results = client.getAllForeignCurrencies();
or supplying the credentials in UserName property
CurrencyInformationServiceClient client = new CurrencyInformationServiceClient();
client.ClientCredentials.UserName.UserName = "someuser";
client.ClientCredentials.UserName.Password = "somepassword";
foreignCurrencyDTO[] results = client.getAllForeignCurrencies();
resulted in
System.ServiceModel.FaultException: Error on verifying message against security policy Error code:1000
Trail #2:
-----------
As per one comment I have seen, I have tried to add the following tag in the binding and call the web service by passing the credentials in UserName property of ClientCredentials
<security authenticationMode="UserNameOverTransport" allowInsecureTransport="true"/>
but the result was
System.ServiceModel.Security.MessageSecurityException: Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.
Trail #3:
-----------
I have tried to use WSHttpBinding instead of the CustomBinding generated by VS as follows:
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
EndpointAddress ea = new EndpointAddress("http://someurl/CurrencyInformationService.jws");
CurrencyInformationServiceClient client = new CurrencyInformationServiceClient(binding, ea);
client.ClientCredentials.UserName.UserName = "someuser";
client.ClientCredentials.UserName.Password = "somepassword";
foreignCurrencyDTO[] results = client.getAllForeignCurrencies();
but the result was
System.ServiceModel.ProtocolException: Content Type application/soap+xml; charset=utf-8 was not supported by service http://someurl/CurrencyInformationService.jws. The client andservice bindings may be mismatched. ---> System.Net.WebException: The remote server returned an error: (415) Unsupported Media Type.
Update:
-----------
I have received a working request from the vendor and tried it in soapUI and it gave a correct response.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<wsse:Security soap:mustUnderstand="1">
<wsse:UsernameToken wsu:Id="SecurityToken-35598fb7-5aa2-4623-b07b-3277c6578beb" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>someuser</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somepassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<getAllForeignCurrencies xmlns="http://www.openuri.org/">
</getAllForeignCurrencies>
</soap:Body>
</soap:Envelope>
Can someone give me a hint how to generate such a SOAP request?
I was facing the same issue while consuming a java web service using .Net, and this thread helped me partially in being able to consume web service.
But, somehow I came across this post and it worked as a final solution for me : http://weblog.west-wind.com/posts/2012/Nov/24/WCF-WSSecurity-and-WSE-Nonce-Authentication
Below settings worked fine for me:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomSoapBinding">
<security includeTimestamp="false"
authenticationMode="UserNameOverTransport"
defaultAlgorithmSuite="Basic256"
requireDerivedKeys="false"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
</security>
<textMessageEncoding messageVersion="Soap11"></textMessageEncoding>
<httpsTransport maxReceivedMessageSize="2000000000"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://notrealurl.com:443/services/RealTimeOnline"
binding="customBinding"
bindingConfiguration="CustomSoapBinding"
contract="RealTimeOnline.RealTimeOnline"
name="RealTimeOnline" />
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
If you use SSL use this:
<basicHttpBinding>
<binding name="NewBinding0">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
If no SSL then use CUB.

Helloworld Mule Rest WS error

I am trying to get the basic http rest helloworld example working in Mule but I get this error
Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException). Message payload is of type: String
This is my config file:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.3/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/3.0/mule-jersey.xsd
http://jersey.apache.org/core http://jersey.apache.org/schemas/core.xsd">
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
</mule>
And my jersey service class
#Path("version")
public class AdminApi {
#GET
#Produces("text/plain")
public String sayHelloWithUri() {
return "Version 999 " ;
}
}
I am trying to access the service using:
http://localhost:8081/api/version
which I believe should be the right url but no luck I always get the above exception message.
Anyone has an idea what this could be?
EDIT:
Root Exception stack trace:
org.mule.api.registry.ResolverException: There are two transformers that are an exact match for input: "class java.lang.String", output: "class java.io.InputStream". Transformers are: "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)" and "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)"
at org.mule.transformer.graph.GraphTransformerResolver.resolve(GraphTransformerResolver.java:65)
at org.mule.registry.TypeBasedTransformerResolver.resolve(TypeBasedTransformerResolver.java:93)
at org.mule.registry.MuleRegistryHelper.resolveTransformer(MuleRegistryHelper.java:265)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Your configuration runs just fine with Mule 3.3.0 (tested outside of Tomcat, in Eclipse) so I suspect the problem comes from either missing or duplicated JARs on your web application classpath.
Check the JARs that get packaged in WEB-INF/lib and potential manually added JARs in Tomcat's /lib directory.
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
and use this url. http://localhost:8081/api/version
result is -Version 999
If you are running with Mule Studio 3.3.0, you must put the mimeType.
Example:
<flow name="RestServiceFlow" doc:name="RestServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP" mimeType="application/json"/>
<jersey:resources doc:name="RESTUTCNotification">
<component class="example.esb.restApi"/>
</jersey:resources>
</flow>

Categories