Mule soap Proxy wsdl fails at relative path resolution of xsd - web-services

I have a WSDL and a Mule SOAP proxy web service using the MuleSoft XML Only SOAP Web Service example.
My application is working fine but if i enable validation i have one issue: When the XSD is stored anywhere other than the root of the project, it will not resolve.
I created folders of service and xsd inside /src/main/resources,
however when the service is invoked I receive the following error:
connector.http.mule.default.receiver.02] org.apache.cxf.wstx_msv_validation.ResolvingGrammarReaderController: D:\Developer\Global\BODs\GetListSalesOrder.xsd (The system cannot find the path specified)
java.io.FileNotFoundException: D:\Developer\Global\BODs\GetListSalesOrder.xsd (The system cannot find the path)
This is my mule flow..
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="test" doc:name="HTTP"/>
<cxf:proxy-service port="SyncSalesOrderBinding" namespace="http://www.cg.com/services/oagis/salesOrder" service="SyncSalesOrderService" validationEnabled="true" payload="body" wsdlLocation="services/WebServices/WSDL/SalesOrder.wsdl" doc:name="CXF">
<cxf:schemaLocations>
<cxf:schemaLocation>services/Developer/Global/BODs/GetListSalesOrder.xsd</cxf:schemaLocation>
</cxf:schemaLocations>
</cxf:proxy-service>
<logger message="Success" level="INFO" doc:name="Logger"/>

If your XSD file is imported in your wsdl file the following Code is fine :-
<cxf:proxy-service port="SyncSalesOrderBinding" namespace="http://www.cg.com/services/oagis/salesOrder" service="SyncSalesOrderService" validationEnabled="true" payload="body" wsdlLocation="services/WebServices/WSDL/SalesOrder.wsdl" doc:name="CXF"/>
You don't need to mention your XSD file in CXF component .. it will validate
If you still face any issues then there is patch available here : https://www.mulesoft.org/jira/browse/MULE-5963?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
.... Please you replace your jar with the one attached to the JIRA ... It will work definately

Related

Can`t enable WS-SecurityPolice with CXF in Web Service

It`s my first project with CXF and Web Services,using Tomcat as a servlet container and my first question in StackOverflow too,so be patient with me....;-)
I'm using :
Tomcat 9 (standalone and integrated with Eclipse).
CXF (3.2.0)
JDK 1.8
Windows 7
**The problem:**WS-SecurityPolicy not enabled/ not working in the server side.
WS-SecurityPolicy is implemented in the wsdl file of the web service and the policy seems working fine,because in the client side the SOAP output message body is signed.
The problem I'm stuck is in the server side,none of the policies are applied in response.
The first issue I had was with the SOAP header "must understand=1",the server does not recognize the security headers and throws an exception.
My suspect was that the web service is not applying the policy,then to avoid the exception of the header I put a handler that does nothing whith it.
Now the server response the SOAP message but in clear form (unsigned, without the BinarySecurityTolen and other stuff),my suspect was true,the policy is not working.
I think the porblem is a misconfiguration of CXF files...
The cxf bean configuration of the web service is loaded during Tomcat's startup.
INFO: Creating Service {http://ole/wsTransaccion}WsTransaccionService from WSDL: wsdl/wsTransaccion.wsdl
....
....
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/cxf-wsTransaccion.xml]
The cxf-wsTransaccion.xml file contains:
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="myPasswordCallback"
class="implementacion.ServerKeystorePasswordCallback" />
<jaxws:endpoint xmlns:tns="http://ole/wsTransaccion" id="wsTransaccion"
implementor="implementacion.WsTransaccionImpl"
wsdlLocation="wsdl/wsTransaccion,wsdl" endpointName="tns:WsTransaccionPort"
serviceName="tns:WsTransaccionService" address="/WsTransaccionPort">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
<jaxws:properties>
<entry key="security.callback-handler">
<ref bean="myPasswordCallback"/>
</entry>
<entry key="security.encryption.properties" value="keystore.properties"/>
<entry key="security.signature.properties" value="keystore.properties"/>
<entry key="ws-security.encryption.username" value="useReqSigCert"/>
</jaxws:properties>
</jaxws:endpoint>
I think the problem coluld be in the location of the file keystore.properties, although no exception is thrown (like a java.io.FileNotFoundException) if not exists..
All examples I saw were Maven's projects ,but this is NOT A MAVEN project so I haven't the folder "resources" where properties files and keystore are placed.
I don't know the right place of keystore.properties, i think must be in the classpath ,then i put it in a package named resources with the keystore together.
The content of keystore.properties:
>org.apache.wss4j.crypto.provider=org.apache.ws.security.components.crypto.Merlin
>org.apache.wss4j.crypto.merlin.keystore.file=server.p12
>org.apache.wss4j.crypto.merlin.keystore.type=PKCS12
>org.apache.wss4j.crypto.merlin.keystore.alias=server
>org.apache.wss4j.crypto.merlin.keystore.password=xxxxxx<br/>
Other possibility is that org.apache.wss4j.crypto.merlin.keystore.file=server.p12 is not in the right place too, although is in the same place like keystore.properties
Any suggestion would be very appreciated.
Thanks very much!!!.
The problem was here:
Tomcat console:
"WARNING: Resource classpath:./resources/policyBinding.xml was not found in the classloaders."Although policyBinding.xml is in the classpath is not properly loaded due to the following annotation in the interface of the web service:
#Policy(uri = "./resources policyBinding.xml",placement=Policy.Placement.DEFAULT)
Thank you to Alfredo (WS-Security Policy node not being generated in Apache CXF with Spring and custom context file
) i figured it out the right syntax:
#Policy(uri = "classpath:policyBinding.xml",placement=Policy.Placement.DEFAULT)

Mule WSDL Connector

I use version 3.8 (3.8.3) .
I basically want to host my wsdl in a different location other than http://{serviceurl}?wsdl like http://{serviceurl}/my-great-service.wsdl
At the following mule doc
https://docs.mulesoft.com/mule-user-guide/v/3.8/wsdl-connectors
it says that you can specify the _wsdlLocation_ property of the CXF endpoint as follows
<endpoint address="wsdl-cxf:http://localhost:8080/book/services/BookService?method=getBooks">
<properties>
<property name="wsdlLocation" value="file:///c:/BookService.wsdl"/>
</properties>
</endpoint>
But where to put this in the mule xml ?
To the root of the file <mule> here </mule> or to <flow> here </flow> or to the <cxf:proxy-service> here </cxf:proxy-service>
The mule documentation is so limited and lock of examples.
Any reason why you are using the cxf connector instead of the web service consumer?
https://docs.mulesoft.com/mule-user-guide/v/3.8/web-service-consumer
All the global configuration elements are specified after the <mule> tag and before the <flow> elements.
Example with web service consumer below:
<mule ......>
<ws:consumer-config name="Web_Service_Consumer" service="ServiceService"
port="ServicePort" serviceAddress="addresUrl"
wsdlLocation="wsdl location" doc:name="Web Service Consumer"/>
<flow>...</flow>
</mule>
If for any reason you want to use the cxf connector, is the same but using the cxf connector

Exposing web service in mule

I want to expose a web service. I have WSDL file with me. I am using CXF proxy service as operation. Now, I have doubt that in Inbound attributes value of port,namespace & service should take from WSDL file only,Right?
If yes, then, after deploying through, http://localhost:8081?wsdl this link am not getting same WSDL which I want to expose.
So, tell me where am I going wrong?Thanks.
To test the project, which URL should use in SoapUI, so that appropriate request XML will generate...
Here is my flow,
<flow name="meterreadingdocumenterpresultbulkcreateconfirmation_outFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:proxy-service configuration-ref="CXF_Configuration" port="MeterReadingDocumentERPResultBulkCreateConfirmation_OutPort" namespace="http://sap.com/xi/IS-U/Global2" service="MeterReadingDocumentERPResultBulkCreateConfirmation_OutService" payload="body" doc:name="CXF" validationEnabled="true"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
After exposing a web service I am not getting proper response...

Duplicating a same SOAP webservice in Camel

A SOAP webservice is been exposed by a system. I have got a wsdl file of the webservice. Im able to send request and get response from soap ui. I want to duplicate this wsdl SOAP webservice in my camel routes deployed in servicemix, thereby making my ESB expose a similar webservice as the system's webservice. THis way many systems access this webservice to contact the system.
How do i duplicate a webservice using wsdl file of the system??
To duplicate webservice, exposed by a system, you can use http proxy route, based on jetty:
<route id="ServiceProxy">
<from uri="jetty:http://0.0.0.0:8186/service/?disableStreamCache=true&matchOnUriPrefix=true&continuationTimeout=900000&httpClient.timeout=120000"/>
<to uri="jetty:http://{{app-server.host}}:{{app-server.http.port}}/service/?bridgeEndpoint=true&throwExceptionOnFailure=false&continuationTimeout=120000&httpClient.timeout=900000"/>
</route>
You can write the same route on JavaDSL.
Found solution - Concept is cxf-proxying
Having a wsdl of the system, create a similar wsdl with the Endpoints defined according to the localhost and port number.
Save the wsdl in your local project,
provide the path to wsdl in pom, for converting wsdl to java by mentioning in the cxf-codegen-plugin.
create cxf consumer bean with details of local wsdl file
<cxf:cxfEndpoint id="consumerProxy" address="http://remote:port/service/"
serviceClass="com.remote.service.RemoteService" endpointName="c:RemoteService"
serviceName="c:RemoteService" xmlns:c="http://remote/namespace/">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE" />
</cxf:properties>
</cxf:cxfEndpoint>
create cxf producer bean with details of remote wsdl file
<cxf:cxfEndpoint id="producerRemote" address="http://localhost:9001/service/"
serviceClass="com.remote.service.RemoteService" endpointName="c:RemoteService"
serviceName="c:RemoteService" xmlns:c="http://remote/namespace/">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE" />
</cxf:properties>
</cxf:cxfEndpoint>
The proxy routes can be like below
from(cxfEndpoint("consumerProxy"))
.to(cxfEndpoint("producerRemote"));
Sending a request to localhost will be consumed by cxf endpoint - consumerProxy and sent to the cxf endpoint - producerRemote.
The response is sent back the reverse way.

Spring and Jax-WS : where are xsd schema?

In spring file applicationConfig.xml, JAX-WS integration need some specific schemas.
I recently successfully use these declarations :
https://jax-ws.dev.java.net/spring/core.xsd
https jax-ws.dev.java.net/spring/servlet.xsd
[I must remove all url (except one) because it's my first question]
The file begins with those declarations :
<beans xmlns="http www.springframework.org/schema/beans"
xmlns:xsi="http www.w3.org/2001/XMLSchema-instance" 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:ws="http jax-ws.dev.java.net/spring/core" xmlns:wss="http jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http www.springframework.org/schema/beans http www.springframework.org/schema/beans/spring-beans.xsd
http www.springframework.org/schema/aop http www.springframework.org/schema/aop/spring-aop.xsd
http www.springframework.org/schema/tx http www.springframework.org/schema/tx/spring-tx.xsd
http www.springframework.org/schema/context http www.springframework.org/schema/context/spring-context.xsd
http jax-ws.dev.java.net/spring/core https jax-ws.dev.java.net/spring/core.xsd
http jax-ws.dev.java.net/spring/servlet https jax-ws.dev.java.net/spring/servlet.xsd">
(...)
<ws:service id="myService" bean="#myWS" />
<wss:binding url="/services/myws" service="#myService" />
Now, a migration occurs for website jax-ws.dev.java.net. These files are not found and I have some errors under Tomcat and Eclipse :
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'https://jax-ws.dev.java.net/spring/core.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
Is there a solution or something to prevent this error ?
Thanks
Finaly I extract XSD from jaxws-spring-1.8.jar (lib for jax-ws to work with Spring).
I put these XSD under WEB-INF directory, just near applicationContext.xml.
I modify declaration of schema in this file with :
http://jax-ws.dev.java.net/spring/core classpath:spring-jax-ws-core.xsd
http://jax-ws.dev.java.net/spring/servlet classpath:spring-jax-ws-servlet.xsd
I have seen the solution here :
Spring schemaLocation fails when there is no internet connection
I suppose you're using maven for building? Try adding the dependency to the pom.xml
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1-1</version>
</dependency>
If you're not using maven, make sure you have jax-ws libs on your classpath.
http://java.net/projects/jax-ws
You don't need to extract the XSD from the jaxws-spring jar.
You just need to make sure the URL you use corresponds to that in the META-INF/spring.schemas file in the jar
They are defined as follows:
http\://jax-ws.dev.java.net/spring/core.xsd=spring-jax-ws-core.xsd
http\://jax-ws.dev.java.net/spring/servlet.xsd=spring-jax-ws-servlet.xsd
http\://jax-ws.dev.java.net/spring/local-transport.xsd=spring-jax-ws-local-transport.xsd
Think you just need to replace https with http. E.g:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd>
For more info on spring.schemas, see here