I try to access the Navision 2009 R2 web service by generating a SOAP message from C#. I get the response only if the codeunit's function I call has no parameters.
Example for codeunit RunJob function Test (no parameters, returns a hardcoded string):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
</Test>
</soap:Body>
</soap:Envelope>
As result I get that string...
Example for same codeunit RunJob function RunJob (takes 1 string parameter named parameter, returns an internal server error):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
<parameter>aaaa</parameter>
</RunJob>
</soap:Body>
</soap:Envelope>
As result I get the error (WebResponse wr = request.GetResponse();) instead of the needed info.
The most interesting thing is that it worked before. The only changes (as for me) - NAV 2013 was installed.
Has anyone experienced the same issue or knows the solution?
P.S.
Here is a part of the web service definition for the RunJob function:
<element name="Runjob">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="parameter" type="string"/>
</sequence>
</complexType>
</element>
<element name="Runjob_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
It was all about the function/variables naming.
The first letter of the each parameter of the function should be small one.
The SOAP body should be like this ("codeunit" is in lowercase, but it's name is as exposed in NAV)
<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/RunJob">
...params...
</RunJob>
the Request header (codeunit name in lower case, function name as it is)
"urn:microsoft-dynamics-schemas/codeunit/runjob:RunJob"
It sound awkward but try to put
<soap:Body><RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
in single line, i.e. no carriage return between Body and RunJob.
Related
Trying to figure out why my SOAP Envelope Action header is not what I expect. I am calling WSO2ESB and communicating with a another WCF service. I am using an NTLMmediator to authenticate to the backend service.
My input transaction looks like this
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.mycompany.com/services/GetProductsByCustomerNbr</a:Action>
<a:MessageID>urn:uuid:448cb5ec-b2d8-4292-b245-5b0d42c0e52a</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://hapq-vpwebtran1.afcorp.afg/AnnuityWebService/VpasAnnuityServiceAdaptor.svc/windows</a:To>
<o:Security s:mustUnderstand="0" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2016-10-10T20:57:42.292Z</u:Created>
<u:Expires>2016-10-14T21:02:42.292Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-83e06bc8-c659-4ddc-845a-de86f0dd19f8-1">
<o:Username>JoeTest</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">JoeTest</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Transaction body
</s:Body>
</s:Envelope>
What my transaction looks like when I write it from inside my mediator and from the value of Envelope from logging in my Proxy Service after my mediator has executed. This is what I exepect the value of Action to be: GetProducesByCustomerNbrResponse
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.mycompany.com/services/GetProductsByCustomerNbrResponse</a:Action>
<a:RelatesTo>urn:uuid:448cb5ec-b2d8-4292-b245-5b0d42c0e52a</a:RelatesTo>
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Transation body
</s:Body>
</s:Envelope>
What it looks like in my wire logs is below. You can see the Action is now GetProductsByCustomerNbr instead of GetPRoductsByCustomerNbrResponse
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="true">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-1">
<wsu:Created>2016-10-13T22:49:45.858Z</wsu:Created>
<wsu:Expires>2016-10-13T22:54:45.858Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
<wsa:MessageID>urn:uuid:d5677050-3ce7-4f11-a269-83c626967b39</wsa:MessageID>
<wsa:Action>http://www.mycompany.com/services/GetProductsByCustomerNbr</wsa:Action>
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Transation body
</s:Body>
</s:Envelope>
I do not understand why I am seeing the input transaction action and not the action from the output. I am sure there is something I am missing or not doing right but I am struggling to find it. If anyone has any thoughts or can point me in the right direction I would appreciate it. If there is any information I failed to provide that would be useful please let me know and I will post it.
I had to add properties to my proxy in order to get this working. Below are the 2 properties I had to add.
disableAddressingForOutMessages so that the ESB was not adding WS-Addressing headers to outgoing messages
PRESERVE_WS_ADDRESSING so that the ESB will forward it on without altering the existing WS-Addressing headers
<property name="disableAddressingForOutMessages" scope="axis2" value="true"/>
<property name="PRESERVE_WS_ADDRESSING" scope="default" value="true"/>
I'm trying to call a web service exposed by third party. After receiving the response I'm wrapping the response to the appropriate class. While marshalling the object of the wrapper class to xml string using "jaxb" I'm getting the error as:
org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#312ea56e
Detailed Stack Trace:
n | BodyType com.unifyv4.ws.CreateOrganisationResponse
n | Body
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
n | ]n | n | Stacktracen |
java.io.IOException:
org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:141)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:83)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline.access$100(Pipeline.java:44)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.Pipeline$1.done(Pipeline.java:139)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:251)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.RedeliveryErrorHandler$1.done(RedeliveryErrorHandler.java:460)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.management.InstrumentationProcessor$1.done(InstrumentationProcessor.java:86)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.processor.SendProcessor$1.done(SendProcessor.java:149)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.component.cxf.CxfClientCallback.handleResponse(CxfClientCallback.java:61)[207:org.apache.camel.camel-cxf:2.15.1.redhat-621084]
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:823)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1644)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1155)[96:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-621084]
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_40]
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)[74:org.apache.cxf.cxf-core:3.0.4.redhat-621084]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_40]
Caused by: org.apache.camel.NoTypeConversionAvailableException: No
type converter available to convert from type:
com.unifyv4.ws.CreateOrganisationResponse to the required type:
java.io.InputStream with value
com.unifyv4.ws.CreateOrganisationResponse#2c9a5080
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:122)[204:org.apache.camel.camel-blueprint:2.15.1.redhat-621084]
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:172)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:138)[235:org.apache.camel.camel-jaxb:2.15.1.redhat-621084]
... 20 more
Below is the blueprint.xml file and class where I'm trying to marshal the response object.
Blueprint.xml
<cxf:rsServer id="crmRequest" address="http://localhost:9002/rest/" serviceClass="com.spectranet.createEnterpriseCustomer.ReceiveEnterpriseRequest" />
<bean id="crmRequestBean" class="com.spectranet.createEnterpriseCustomer.ReceiveEnterpriseRequest" />
<bean id="myProcessor" class="com.spectranet.createEnterpriseCustomer.MyProcessor" />
<bean id="myProcessor2" class="com.spectranet.createEnterpriseCustomer.MyProcessor2" />
<bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader">
<argument index="0" ref="myCamel" />
<argument index="1" ref="createOrg" />
</bean>
<bean id="createOrg" class="org.apache.camel.converter.dozer.DozerBeanMapperConfiguration">
<property name="mappingFiles">
<list>
<value>transformation.xml</value>
</list>
</property>
</bean>
<cxf:cxfEndpoint id="unifyCreateOrg" address="http://203.122.58.158:9080/unifyejb/CRMAPI" serviceClass="com.unifyv4.ws.CRMAPI" serviceName="com.unifyv4.ws.CRMAPIService" wsdlURL="wsdl/CRMAPI_WSDL.wsdl" />
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint">
<endpoint uri="dozer:createOrg?sourceModel=com.spectranet.createEnterpriseCustomer.CRMCAFRequest&targetModel=com.unifyv4.ws.CreateOrganisation&mappingFile=transformation.xml" id="crmToUnify"/>
<dataFormats>
<jaxb contextPath="generated" id="generated"/>
<jaxb contextPath="com.unifyv4.ws" prettyPrint="true" encoding="UTF-8" partClass="com.unifyv4.ws.CreateOrganisationResponse" id="myPartialJaxb"/>
</dataFormats>
<route>
<from uri="cxfrs:bean:crmRequest" id="crmRequest">
<description/>
</from>
<convertBodyTo type="com.spectranet.createEnterpriseCustomer.CRMCAFRequest"/>
<to pattern="InOut" ref="crmToUnify"/>
<setHeader headerName="Username">
<constant>admin</constant>
</setHeader>
<setHeader headerName="Password">
<constant>admin</constant>
</setHeader>
<setHeader headerName="operationName">
<constant>createOrganisation</constant>
</setHeader>
<setHeader headerName="operationNameSpace">
<constant>http://ws.unifyv4.com/</constant>
</setHeader>
<log message="customer: ${in.body.organisation.customer}"/>
<log message="ipAddress: ${in.body.sessionObject.ipAddress}"/>
<process ref="myProcessor"/>
<to pattern="InOut" uri="cxf:bean:unifyCreateOrg"/>
<marshal ref="myPartialJaxb"/>
<log message="Messsage from soap call is : ${body}"/>
</route>
</camelContext>
Java Code to Marshal the object to xml.
package com.spectranet.createEnterpriseCustomer;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import com.unifyv4.ws.CreateOrganisationResponse;
import com.unifyv4.ws.Organisation;
public class MyProcessor2 implements Processor {
public void process(Exchange exchng) throws Exception {
CreateOrganisationResponse orgResponse = new CreateOrganisationResponse();
orgResponse.setReturn(exchng.getIn().getBody(Organisation.class));
System.out.println("Organisation Created : " + orgResponse.getReturn().getOrgNo());
exchng.getIn().setBody(orgResponse);
}
}
Kindly please provide any suggestions if any.
First of all, may I know why you want to marshal ?
Looking at route, I dont think you need to marshal any payload.
Just play around XPATH, XSLT & Camel. Camel becomes more complicated in-fact, if you want to marshal and unmarshal. I am not saying its wrong, I am saying its easier without the hassle of marshal, unmarshal, etc. Because ultimately thats what all frameworks do internally. :)
Eg: https://github.com/gnanagurus/camel-guru-projects/tree/master/camel-cxf-geocoder-example
Cheers
This issue can come when the generated class does not contain XML root element tag. Because of it, framework can not explicitly convert the objects to XML and vice versa.
Hence you are creating the response via processor, please refer your WSDL and create the wrapper response as well.
Thanks
Shiv
I have been using Authorize.NET's GetCustomerProfile for many years and suddenly today the response is not returning a payment profile. It just returns an array of profiles, but all important fields (such as payment) are null.
(This is part of their CIM feature where an 'obfuscated' payment profile is returned and should be something like XXXX1234)
I am using a generated proxy within Visual Studio to the URL https://api.authorize.net/soap/v1/Service.asmx?WSDL (which generates a References.cs file)
I had a similar issue on the CreateCustomerPaymentProfile SOAP call (via .NET auto-generated proxy) that just started yesterday, 11/3/2015, even though we've been successfully interfacing the SOAP CIM for a couple years.
I was able to "fix" the issue by doing an "Update Service Reference" in Visual Studio to regenerate the proxy classes based on their latest WSDL. There were several changes in the WSDL.
Specifically, on my end it appeared as if the response was not including a value for the customerPaymentProfileId after being successfully created on their end. In reality, they were in fact still sending this value, but there was a new field above it in the XML response, customerProfileId. As Simon_Weaver mentioned in his answer, the proxy classes generated by Visual Studio have explicit ordering of fields that are required for proper deserialization. The addition of this previously "unknown" field above a known field caused it to break my code.
Luckily this new customerProfileId was included in their latest WSDL so an "Update Service Reference" and recompile fixed my issue.
I informed Authorize.net support of my issue in great detail and told them they need to include any new fields at the end of the "sequence" in the WSDL document in order to not break and clients using older versions of the WSDL. So far I have not heard a response from them, but I would encourage anyone else who experienced this issue, even if you've already worked-around it, to report it to them at support#authorize.net so they don't accidently do this again.
Well hello Simon!
It looks like Authorize.NET updated their service with new fields but forgot to add them to the WSDL.
This is a sample request that I sent (intercepted using Fiddler):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo3vYq2eC/5VIuiUcm2hEtw8AABBBJr/dLQF7z02Y7UKwphq24W1n9j0XlQ1MiAlOjy5fO14ACQAA</VsDebuggerCausalityData>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetCustomerProfile xmlns="https://api.authorize.net/soap/v1/">
<merchantAuthentication>
<name>95U6bwXXXXX</name>
<transactionKey>8tf62gV7XXXXXX</transactionKey>
</merchantAuthentication>
<customerProfileId>37745529</customerProfileId>
</GetCustomerProfile>
</s:Body>
</s:Envelope>
This is the response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCustomerProfileResponse xmlns="https://api.authorize.net/soap/v1/">
<GetCustomerProfileResult>
<resultCode>Ok</resultCode>
<messages>
<MessagesTypeMessage>
<code>I00001</code>
<text>Successful.</text>
</MessagesTypeMessage>
</messages>
<profile>
<merchantCustomerId>33938</merchantCustomerId>
<email>4691705#EXAMPLE.COM</email>
<customerProfileId>37745529</customerProfileId>
<paymentProfiles>
<CustomerPaymentProfileMaskedType>
<billTo>
<firstName>TEST</firstName>
<lastName>USER</lastName>
<company>Defender Razor</company>
<address>1 RODEO DRIVE</address>
<city>BEVERLY HILLS</city>
<state>CA</state>
<zip>90210</zip>
<country>UNITED STATES</country>
</billTo>
<customerProfileId>0</customerProfileId>
<customerPaymentProfileId>34313485</customerPaymentProfileId>
<payment>
<creditCard>
<cardNumber>XXXX5108</cardNumber>
<expirationDate>XXXX</expirationDate>
</creditCard>
</payment>
</CustomerPaymentProfileMaskedType>
</paymentProfiles>
</profile>
</GetCustomerProfileResult>
</GetCustomerProfileResponse>
</soap:Body>
</soap:Envelope>
Everything here is correct - as you can see the payment node is being sent correctly.
However - with .NET deserialization the order of attributes matters - as specified in the generated References.cs file.
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
It turns out that two new fields were added to the response billTo and customerProfileId but they weren't added to the WSDL.
So when trying to deserialize the field billTo is found but that isn't what was expected - so everything ends up null.
If you add these two lines (and be careful to add them to exactly this type) then you can regenerate the references.cs file (by right clicking on the service reference and regenerating the file).
If you were generating your proxy from the URL https://api.authorize.net/soap/v1/Service.asmx?WSDL then you will need to download this file locally as Service.wsdl and generate the proxy from there.
<s:element minOccurs="1" maxOccurs="1" name="billTo" type="tns:CustomerAddressType"/>
<s:element minOccurs="1" maxOccurs="1" name="customerProfileId" type="s:long" />
<s:complexType name="CustomerPaymentProfileMaskedType">
<s:complexContent mixed="false">
<s:extension base="tns:CustomerPaymentProfileBaseType">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="billTo" type="tns:CustomerAddressType"/>
<s:element minOccurs="1" maxOccurs="1" name="customerProfileId" type="s:long" />
<s:element minOccurs="1" maxOccurs="1" name="customerPaymentProfileId" type="s:long" />
<s:element minOccurs="0" maxOccurs="1" name="payment" type="tns:PaymentMaskedType" />
<s:element minOccurs="0" maxOccurs="1" name="driversLicense" type="tns:DriversLicenseMaskedType" />
<s:element minOccurs="0" maxOccurs="1" name="taxId" type="s:string" />
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
I lost over 12 hours of payments before this was detected. Fortunately I have the customer's emails but this was very bad. You can't just add fields to a response where the order matters. And even worse than that you can't just forget to add them to the WSDL.
This was the quick fix for me. I may switch to using the proper API at some point - and I've reported this to Authorize.net hoping they may respond too.
This is the differences in References.cs after I made my change. As you can see the Order property has been incremented :
I would like to make request to web service from mule flow. So far I got WSDL generate classes (wsdl2java), prepared flow (below), and "successfully" send request. Now, problem is, that even thou I have taken base class from generated class and put it in payload it does not generate required soap.
My flow:
<flow name="flow1" doc:name="flow1">
<quartz:inbound-endpoint jobName="testingJob" repeatInterval="10810000" repeatCount="0" startDelay="5000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job groupName="g1job" jobGroupName="g1job">
<quartz:payload>a</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<logger message="Starting quartz for testing purpouses" level="INFO" doc:name="Logger"/>
<custom-transformer class="com.example.GenerateSimpleRoutePublish" doc:name="Java"/>
<cxf:simple-client doc:name="SOAP" serviceClass="com.example.ws.MyWebService" operation="send">
</cxf:simple-client>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9094" path="sync-server-web/services/myws" method="POST" connector-ref="http_internal" doc:name="HTTP"/>
</flow>
GenerateSimpleRoutePublish just put base object into payload and move on.
Result that is sent as soap request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:arg0>
<ns1:MyRequest>
...
But it should look like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:send xmlns:ns1="http://somenamespace.si/">
<ns1:MyRequest>
...
Notice that is not there anymore in desired xml.
Anyone knows how to achieve that? I did googled a lot but just don't find right solution. If more is required then I can provide info.
Thanks!
EDIT
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="MyWebService" targetNamespace="http://ws.example.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://ws.example.com/"
version="1.0" xmlns:tns="http://ws.example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyRequest" type="tns:MyRequest" />
<xs:element name="send" type="tns:send" />
<xs:element name="sendResponse" type="tns:sendResponse" />
<xs:complexType name="send">
<xs:sequence>
<xs:element minOccurs="0" ref="tns:MyRequest" />
</xs:sequence>
</xs:complexType>
<xs:complexType final="extension restriction" name="MyRequest">
<xs:complexContent>
...
Transformer class GenerateSimpleRoutePublish.java:
#Override
public MuleEvent process(MuleEvent event) throws MuleException {
event.setMessage(transformMessage(event.getMessage(), event.getEncoding()));
// TODO Auto-generated method stub
return event;
}
public MuleMessage transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
MyRequest myRequest = new MyRequest();
/**
* some filling of testing data that is formatted correctly when soap is sent.
*/
Send send = new Send();
send.setMSyequest(myRequest);//the only setter method available for Send
message.setPayload(send);
return message;
}
Send.java methods and xml definition:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "send", propOrder = {"myRequest"})
public MyRequest getMyRequest()
public void setMyRequest(MyRequest value)
Instead of using a custom-transformer you could use Groovy script to send SOAP request to webservice client just as Java pojo class... Please check the reference :- https://m-square.com.au/consuming-net-wcf-soap-web-services-from-mule/
I have serached this question on Stackoverflow and found some similar questions but none of them solved my issue. I have compiled all the "proposed" solution but NOTHING works :-(
I have a wsdl and I generated the client code using adb client(Axis 2). The wsdl says that this request will be sent over Https url. I able to successfully create a stub using wsdl to java. However I am not sure how to Basic authentication. The documentation which tells me the details also says that I user name and pwd should be encoded using Base64.
The authentication method used is HTTP Basic . The user name and
password will need to be encoded in a base64 format – UTF8 character
set.
Example: Username:Password = “VXNlcm5hbWU6UGFzc3dvcmQ=”
BTW I have tried this wsdl in SOAP UI and and I am getting correct response but some how my java code won't work
Now Here is the wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="urn:OTSB2B" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:OTSB2B" xmlns:intf="urn:OTSB2B" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="urn:OTSB2B" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:urn="urn:OTSB2B">
<simpleType name="tn">
<restriction base="string">
<length value="10"/>
</restriction>
</simpleType>
<simpleType name="prov">
<restriction base="string">
<length value="2"/>
<enumeration value="on"/>
<enumeration value="qc"/>
</restriction>
</simpleType>
<element name="getPresaleByTN">
<complexType>
<sequence>
<element name="tn" type="urn:tn"/>
<element name="prov" type="urn:prov"/>
</sequence>
</complexType>
</element>
<element name="getPresaleByTNReturn" type="xsd:string"/>
<element name="isAlive"/>
<element name="isAliveReturn" type="xsd:boolean"/>
</schema>
</wsdl:types>
<message name="isAliveRequest">
<part element="impl:isAlive" name="isAlive"/>
</message>
<message name="getPresaleByTNRequest">
<part element="impl:getPresaleByTN" name="getPresaleByTN"/>
</message>
<message name="isAliveResponse">
<part element="impl:isAliveReturn" name="isAliveReturn"/>
</message>
<message name="getPresaleByTNResponse">
<part element="impl:getPresaleByTNReturn" name="getPresaleByTNReturn"/>
</message>
<portType name="GetPresaleByTN">
<operation name="getPresaleByTN">
<input message="impl:getPresaleByTNRequest" name="getPresaleByTNRequest"/>
<output message="impl:getPresaleByTNResponse" name="getPresaleByTNResponse"/>
</operation>
<operation name="isAlive">
<input message="impl:isAliveRequest" name="isAliveRequest"/>
<output message="impl:isAliveResponse" name="isAliveResponse"/>
</operation>
</portType>
<binding name="DominoSoapBinding" type="impl:GetPresaleByTN">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getPresaleByTN">
<wsdlsoap:operation soapAction=""/>
<input name="getPresaleByTNRequest">
<wsdlsoap:body use="literal"/>
</input>
<output name="getPresaleByTNResponse">
<wsdlsoap:body use="literal"/>
</output>
</operation>
<operation name="isAlive">
<wsdlsoap:operation soapAction=""/>
<input name="isAliveRequest">
<wsdlsoap:body use="literal"/>
</input>
<output name="isAliveResponse">
<wsdlsoap:body use="literal"/>
</output>
</operation>
</binding>
<service name="GetPresaleByTNService">
<port binding="impl:DominoSoapBinding" name="Domino">
<wsdlsoap:address location="https://b2b.ivv.bell.ca/ots-qualification-service-tn"/>
</port>
</service>
</definitions>
I have tried this:
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
client.addStringHeader(new QName("userName"), "XXX");
client.addStringHeader(new QName("password"), "YYYYYYYY");
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives me following error:
org.apache.axis2.AxisFault: Failed to add string header, you have to
have namespaceURI for the QName at
org.apache.axis2.client.ServiceClient.addStringHeader(ServiceClient.java:434)
at com.dinesh.bellAxis.App.main(App.java:30)
Then I tried this
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername("XXX");
basicAuth.setPassword("CCCCC");
basicAuth.setPreemptiveAuthentication(true);
stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives me the following error:
org.apache.axis2.AxisFault: Transport level information does not match
with SOAP Message namespace URI at
org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:90)
at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at
com.acn.client.GetPresaleByTNServiceStub.getPresaleByTN(GetPresaleByTNServiceStub.java:460)
Next I tried this: which I think is incorrect as it WS Security and not basic auth but what the heck I exhausted all my options
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMElement omSecurityElement = omFactory.createOMElement(new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"), null);
OMElement omusertoken = omFactory.createOMElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"), null);
OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);
omuserName.setText("XXXX");
OMElement omPassword = omFactory.createOMElement(new QName("", "Password", "wsse"), null);
omPassword.addAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText",null );
omPassword.setText("YYYYYYY");
omusertoken.addChild(omuserName);
omusertoken.addChild(omPassword);
omSecurityElement.addChild(omusertoken);
stub._getServiceClient().addHeader(omSecurityElement);
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot
create a prefixed element with an empty namespace name at
org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186)
at
org.apache.axiom.om.impl.llom.OMElementImpl.(OMElementImpl.java:161)
at
org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126)
at com.dinesh.bellAxis.App2.main(App2.java:37)
I am not sure what to do next and have checked all the documentation on Apache Axis2 and googled all over the place but could get the code to work.
Any suggestions
Code fragments 1 and 3 don't work because they attempt to create a message that is invalid with respect to SOAP (fragment 1) or XML (fragment 3). Anyway, they attempt to add SOAP headers to the message, which is not what basic auth is about.
Code fragment 2 looks correct. From the stack trace of the exception (more precisely the presence of the handleResponse method) you can see that there is an issue with the response. The error message likely indicates that the content type of the response doesn't match the SOAP version actually used in the response. This means that there is a problem with the service, not with the client.
I found the answer after a lot of trial and error and going over SAAj tutorial on Oracle website.
I able to do Basic authentication using this
String authorization = new sun.misc.BASE64Encoder().encode((“myUserName”+”:”+”myPassword”).getBytes());
headers.addHeader(“Authorization”, “Basic ” + authorization);
Here's the complete tutorial - http://www.javahabit.com/2014/10/17/quick-tutorial-saaj-api/