I have generated stub for a webserivce using apache axis2 and I want to add custom soap header to the request. I want the soap header to look like this
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0">
<ns1:Username>myuser</ns1:Username>
<ns1:Password>mypass</ns1:Password>
</ns1:soapHeader>
</soapenv:Header>
and I am writing this code
org.apache.axiom.soap.SOAPEnvelope env = null;
org.apache.axiom.om.OMFactory omFactory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
org.apache.axiom.om.OMElement omElement = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "soapHeader", "ns1"));
org.apache.axiom.om.OMElement omElement1 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Username", "ns1"));
org.apache.axiom.om.OMElement omElement2 = omFactory.createOMElement(new javax.xml.namespace.QName("urn:oasis:names:core", "Password", "ns1"));
omElement.addChild(omElement1);
omElement.addChild(omElement2);
omElement1.setText("myuser");
omElement2.setText("mypass");
addHeader(omElement, env);
but I am not getting the required soap header. This is what im getting
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:soapHeader xmlns:ns1="urn:oasis:names:core" soapenv:mustUnderstand="0">
<ns1:Username>myuser</ns1:Username>
</ns1:soapHeader>
</soapenv:Header>
as you can see password is missing. I want to know what I am doing wrong.
Related
I'm a project than I generate a wsdl client with apache cfx.
When I run my project in mi local machine with Windows it works perfectlly, but when I was to try in machine with SO Linux (Red hat) it didn't work.
My xml since Windows is:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header>
<wsse:Security 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'>
<wsse:UsernameToken wsu:Id='UsernameToken-3e963a94-b8fc-4876-ace8-b675f270d3a0'>
<wsse:Username>myusername</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>mypass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<ns4:HeaderReq xmlns:ns4='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns2='http://www.something.com/ws/iss/nameWebConsume' locale='es_MX' codIdioma='UTF-8'>
<Deploy>
***
</Deploy>
<Access>
***
</Access>
<Consumer>
***
</Consumer>
<RequestData>
***
</RequestData>
</ns4:HeaderReq>
</env:Header>
<env:Body>
<CheckSomething xmlns='http://www.something.com/ws/nss/nameWebConsume' xmlns:ns4='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns2='http://www.something.com/ws/iss/nameWebConsume'>
<Folio>123456789</Folio>
</CheckSomething>
</env:Body>
</env:Envelope>
My xml since linux is:
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Header>
<wsse:Security 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'>
<wsse:UsernameToken wsu:Id='UsernameToken-9d835b01-63d0-4d88-9d15-6c06b73531a2'>
<wsse:Username>myusername</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>mypass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<ns2:HeaderReq xmlns:ns2='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns4='http://www.something.com/ws/iss/nameWebConsume' codIdioma='UTF-8' locale='es_MX'>
<Deploy>
***
</Deploy>
<Access>
***
</Access>
<Consumer>
***
</Consumer>
<RequestData>
***
</RequestData>
</ns2:HeaderReq>
</soap:Header>
<soap:Body>
<ns4:CheckSomething xmlns:ns2='http://www.something.com/ws/nss/general/Headers' xmlns:ns3='http://www.something.com/ws/nss/common/ExcepcionGeneral' xmlns:ns4='http://www.something.com/ws/iss/nameWebConsume'>
<Folio>123456789</Folio>
</ns4:CheckSomething>
</soap:Body>
</soap:Envelope>
As you can see there are different tags from both SO, my question is: How I can create the same xml request to consume wsdl service?
My code configuration in classes, every header looks like I post
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "HeaderRequestType", propOrder = {
"deploy",
"access",
"consumer",
"requestData"
})
public class HeaderRequestType {...}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "CheckSomething", namespace = "http://www.something.com/ws/iss/nameWebConsume", propOrder = {
"folio"
})
public class CheckSomething {...}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "Deploy", propOrder = {
...
})
public class Deploy {...}
My interface where I consume SOAP
#WebService(targetNamespace = "http://www.something.com/ws/iss/nameWebConsume", name = "nameWebConsume")
#XmlSeeAlso({ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface CheckSomething {
#WebMethod
public void CheckSomething(
#WebParam(partName = "request", name = "CheckSomethingIn", targetNamespace = "http://www.something.com/ws/iss/nameWebConsume") CheckSomethingInType request,
#WebParam(partName = "headerRequest", name = "HeaderReq", targetNamespace = "http://www.something.com/ws/nss/general/Headers", header = true) HeaderRequestType headerRequest,
#WebParam(partName = "response", mode = WebParam.Mode.OUT, name = "CheckSomethingOut", targetNamespace = "http://www.something.com/ws/iss/nameWebConsume") javax.xml.ws.Holder<CheckSomethingOutType> response,
#WebParam(partName = "headerResponse", mode = WebParam.Mode.OUT, name = "HeaderRes", targetNamespace = "http://www.something.com/ws/nss/general/Headers", header = true) javax.xml.ws.Holder<HeaderResponseType> headerResponse
) throws CheckSomethingFault;
}
That's it.
I you need more files where I have configuration I will update my post.
Update 1
I have a response in windows good (with data) and when I try in linux I have an error says: Error in data integration cvc-complex-type 2.4: in element
I have a JAX-WS Client generated from WSDL files.
Setting Headers worked so far with following code:
WSBindingProvider bp = (WSBindingProvider) port;
bp.setOutboundHeaders(
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "To", "wsa"), "--To--"),
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "Action", "wsa"), "--Action--"),
Headers.create(new QName("http://schemas.xmlsoap.org/ws/2005/08/addressing", "MessageID", "wsa"), UUID.randomUUID().toString())
);
Which produces (as desired) the following XML snippet:
<S:Header>
<To
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">--to--
</To>
<Action
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">--action--
</Action>
<MessageID
xmlns="http://schemas.xmlsoap.org/ws/2005/08/addressing">fe1b400a-e724-4486-8618-b1d36a0acbbb
</MessageID>
</S:Header>
But I need the following chained Tags, which I couldn't acheive with Headers.create(...):
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="PartnerId" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>--username--</wsse:Username>
</wsse:UsernameToken>
</wsse:Security>
Any ideas how I can add this to the header?
The following code works for me:
private static final String SCHEMA = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static final String SCHEMA_PREFIX = "wsse";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
// Create a SOAP header
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader header = soapEnvelope.getHeader();
// Add the security SOAP header element
SOAPHeaderElement security = header.addHeaderElement(new QName(SCHEMA, "Security", SCHEMA_PREFIX));
SOAPElement usernameToken = security.addChildElement("UsernameToken", SCHEMA_PREFIX);
SOAPElement usernameElement = usernameToken.addChildElement("Username", SCHEMA_PREFIX);
SOAPElement passwordElement = usernameToken.addChildElement("Password", SCHEMA_PREFIX);
Name typeName = soapEnvelope.createName("type");
passwordElement.addAttribute(typeName, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
usernameElement.setTextContent(USERNAME);
passwordElement.setTextContent(PASSWORD);
((WSBindingProvider) webServicePort).setOutboundHeaders(Headers.create(security));
} catch (SOAPException e) {
logger.severe("Error setting SOAP header");
e.printStackTrace();
}
The XML is as follows:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<env:Header>
<wsse:Security env:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</env:Header>
<env:Body>
...
I am new to SOAP,I want to create SOAP request,as given below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<SOAP-ENV:Header/>
<soapenv:Body>
<tem:RequestData>
<tem:requestDocument>
<![CDATA[
<Request>
<Authentication CMId="68" Function="1" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR"/>
<Establishment Id="4297867"/>
</Request>
]]>
</tem:requestDocument>
</tem:RequestData>
</soapenv:Body>
</soapenv:Envelope>
Code for creating SOAP request i have found in tutorial
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage sm = mf.createMessage();
SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/");
envelope.setPrefix("soapenv");
envelope.setAttribute("xmlns:tem", "http://tempuri.org/");
SOAPBody body = envelope.getBody();
body.setPrefix("soapenv");
SOAPElement requestData = body.addChildElement("RequestData");
requestData.setPrefix("tem");
SOAPElement requestDoc = requestData.addChildElement("requestDocument","tem","http://tempuri.org/");
requestDoc.addTextNode(" <![CDATA[");
SOAPElement request = requestDoc.addChildElement("Request");
SOAPElement authentication = request.addChildElement("Authentication");
authentication.setAttribute("CMId", "68");
authentication.setAttribute("Guid", "5594FB83-F4D4-431F-B3C5-EA6D7A8BA795");
authentication.setAttribute("Password", "poihg321TR");
authentication.setAttribute("Function", "1");
SOAPElement establishment = request.addChildElement("Establishment");
establishment.setAttribute("Id", "4297867");
requestDoc.addTextNode("]]>");
System.out.println("\nSoap Request: \n\n\n"+getMsgAsString(sm));
Output I am getting is when executing the code.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><SOAP-ENV:Header/><soapenv:Body><tem:RequestData><tem:requestDocument xmlns:tem="http://tempuri.org/"> <![CDATA[<Request><Authentication CMId="68" Function="1" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR"/><Establishment Id="4297867"/></Request>]]></tem:requestDocument></tem:RequestData></soapenv:Body></soapenv:Envelope>
The problem is
<![CDATA[ ]]> is displaying like <![CDATA[ and ]]>
And my Server is not accepting this request.
You need to create and add a CDATASection:
CDATASection cdata =
requestDoc.getOwnerDocument().createCDATASection("<element>text</element>");
requestDoc.appendChild(cdata);
This will produce:
<![CDATA[<element>text</element>]]>
Hi I'm trying to create a Paypal Recurring Pyament using the JAVA Merhant SDK but I keep having "invalid token" when trying to call "createRecurringPaymentsProfile" method.
Here are the Request and Response
For SetExpressCheckout Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
<soapenv:Header>
<ns:RequesterCredentials>
<ebl:Credentials>
<ebl:Username>XXX</ebl:Username>
<ebl:Password>XXX</ebl:Password>
<ebl:Signature>XXX</ebl:Signature>
</ebl:Credentials>
</ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<ns:SetExpressCheckoutReq>
<ns:SetExpressCheckoutRequest>
<ebl:Version>109.0</ebl:Version>
<ebl:SetExpressCheckoutRequestDetails>
<ebl:ReturnURL>http://127.0.0.1:8888/ReturnURL</ebl:ReturnURL>
<ebl:CancelURL>http://127.0.0.1:8888/CancelURL</ebl:CancelURL>
<ebl:BillingAgreementDetails>
<ebl:BillingType>RecurringPayments</ebl:BillingType>
<ebl:BillingAgreementDescription>Buyer is billed at "USD1.00" per month
</ebl:BillingAgreementDescription>
</ebl:BillingAgreementDetails>
<ebl:PaymentDetails>
<ebl:OrderTotal currencyID="USD">1.00</ebl:OrderTotal>
<ebl:ItemTotal currencyID="USD">1</ebl:ItemTotal>
<ebl:ButtonSource>PayPal_SDK</ebl:ButtonSource>
<ebl:NotifyURL>/NotifyURL</ebl:NotifyURL>
<ebl:PaymentAction>Sale</ebl:PaymentAction>
</ebl:PaymentDetails>
</ebl:SetExpressCheckoutRequestDetails>
</ns:SetExpressCheckoutRequest>
</ns:SetExpressCheckoutReq>
</soapenv:Body>
This the response
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
<SOAP-ENV:Header>
<Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"></Security>
<RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
<Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
<Username xsi:type="xs:string"></Username>
<Password xsi:type="xs:string"></Password>
<Signature xsi:type="xs:string"></Signature>
<Subject xsi:type="xs:string"></Subject>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body id="_0">
<SetExpressCheckoutResponse xmlns="urn:ebay:api:PayPalAPI">
<Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-04-05T22:23:40Z</Timestamp>
<Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack>
<CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">6c19207a14fd</CorrelationID>
<Version xmlns="urn:ebay:apis:eBLBaseComponents">109.0</Version>
<Build xmlns="urn:ebay:apis:eBLBaseComponents">10463669</Build>
<Token xsi:type="ebl:ExpressCheckoutTokenType">EC-1X212344K9178491M</Token>
</SetExpressCheckoutResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
In CreateRecurringPaymentsProfile Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
<soapenv:Header>
<ns:RequesterCredentials>
<ebl:Credentials>
<ebl:Username>XXX</ebl:Username>
<ebl:Password>XXX</ebl:Password>
<ebl:Signature>XXX</ebl:Signature>
</ebl:Credentials>
</ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<ns:CreateRecurringPaymentsProfileReq>
<ns:CreateRecurringPaymentsProfileRequest>
<ebl:Version>109.0</ebl:Version>
<ebl:CreateRecurringPaymentsProfileRequestDetails>
<ebl:Token>EC-1X212344K9178491M</ebl:Token>
<ebl:RecurringPaymentsProfileDetails>
<ebl:BillingStartDate>2014-04-06T13:21:36Z</ebl:BillingStartDate>
</ebl:RecurringPaymentsProfileDetails>
<ebl:ScheduleDetails>
<ebl:Description>Buyer is billed at "USD1.00" per month</ebl:Description>
<ebl:PaymentPeriod>
<ebl:BillingPeriod>Month</ebl:BillingPeriod>
<ebl:BillingFrequency>12</ebl:BillingFrequency>
<ebl:Amount currencyID="USD">1.00</ebl:Amount>
</ebl:PaymentPeriod>
</ebl:ScheduleDetails>
</ebl:CreateRecurringPaymentsProfileRequestDetails>
</ns:CreateRecurringPaymentsProfileRequest>
</ns:CreateRecurringPaymentsProfileReq>
</soapenv:Body>
</soapenv:Envelope>
The response was an "invalid token"
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
<SOAP-ENV:Header>
<Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"></Security>
<RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
<Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
<Username xsi:type="xs:string"></Username>
<Password xsi:type="xs:string"></Password>
<Signature xsi:type="xs:string"></Signature>
<Subject xsi:type="xs:string"></Subject>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body id="_0">
<CreateRecurringPaymentsProfileResponse xmlns="urn:ebay:api:PayPalAPI">
<Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2014-04-05T22:28:11Z</Timestamp>
<Ack xmlns="urn:ebay:apis:eBLBaseComponents">Failure</Ack>
<CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">50e773299b36f</CorrelationID>
<Errors xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:ErrorType">
<ShortMessage xsi:type="xs:string">Invalid Token</ShortMessage>
<LongMessage xsi:type="xs:string">The token is invalid</LongMessage>
<ErrorCode xsi:type="xs:token">11502</ErrorCode>
<SeverityCode xmlns="urn:ebay:apis:eBLBaseComponents">Error</SeverityCode>
</Errors>
<Version xmlns="urn:ebay:apis:eBLBaseComponents">109.0</Version>
<Build xmlns="urn:ebay:apis:eBLBaseComponents">10433064</Build>
<CreateRecurringPaymentsProfileResponseDetails xmlns="urn:ebay:apis:eBLBaseComponents"
xsi:type="ebl:CreateRecurringPaymentsProfileResponseDetailsType">
<ProfileID xsi:type="xs:string"></ProfileID>
<TransactionID xsi:type="xs:string"></TransactionID>
</CreateRecurringPaymentsProfileResponseDetails>
</CreateRecurringPaymentsProfileResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I'm sure that the CreateRecurringPaymentsProfile Request token is the response token from SetExpressCheckout.
To answer my question.
OrderTotal should be seto to "0" and ItemTotal should be removed in SetExpressCheckout Request.
But the "invalid token error" is not very helpful error message.
After you SetExpressCheckOutResponse include the following code,
Map<String, String> sdkConfig = new HashMap<String, String>();
sdkConfig.put("mode", "sandbox");
sdkConfig.put("mode", "sandbox");
sdkConfig.put("acct1.UserName", apiUsername);
sdkConfig.put("acct1.Password", apiPassword);
sdkConfig.put("acct1.Signature", apiSignature);
SimpleDateFormat formatterR = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:sssz");
CreateRecurringPaymentsProfileReq createRecurringPaymentsProfileReq = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();
RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType();
recurringPaymentsProfileDetails.setBillingStartDate(formatterR.format(new Date()));
recurringPaymentsProfileDetails.setSubscriberName("YOUR SUBSCRIBER NAME");
BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, "1.00");
//I Take as MONTHLY Recurrence
//So that i set periodType as MONTH, frequency as 1 (for every month) and billing amount here i sent as 1 USD
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(BillingPeriodType.MONTH, Integer.parseInt("1"), billingAmount);
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType("Description about payment", paymentPeriod); //description, paymentPeriod object
CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType(recurringPaymentsProfileDetails, scheduleDetails);
AddressType addressType = new AddressType();
addressType.setStateOrProvince("STATE");
addressType.setCityName("CITY");
addressType.setCountryName("COUNTRY");
PersonNameType personName = new PersonNameType();
personName.setFirstName("SUBSCRIBER FIRST NAME");
personName.setLastName("SUBSCRIBER LAST NAME");
PayerInfoType payerInfoType = new PayerInfoType();
payerInfoType.setAddress(addressType);
payerInfoType.setPayerName(personName);
CreditCardDetailsType creditCard = new CreditCardDetailsType();
//creditCard.setCreditCardType(CreditCardTypeType.VISA);
// Credit Card Number
creditCard.setCreditCardNumber("CARD NO");//4442662639546634
// Credit Card Expiration Month
creditCard.setExpMonth(12);//Integer.parseInt("12")
// Credit Card Expiration Year
creditCard.setExpYear(Integer.parseInt(2016);//Integer.parseInt("2016")
creditCard.setCVV2("CVV CODE");
creditCard.setCardOwner(payerInfoType);
createRecurringPaymentsProfileRequestDetails.setCreditCard(creditCard);
createRecurringPaymentsProfileRequest
.setCreateRecurringPaymentsProfileRequestDetails(createRecurringPaymentsProfileRequestDetails);
createRecurringPaymentsProfileReq
.setCreateRecurringPaymentsProfileRequest(createRecurringPaymentsProfileRequest);
PayPalAPIInterfaceServiceService service = null;
try {
service = new PayPalAPIInterfaceServiceService(sdkConfig);
} catch (Exception e) {
LOGGER.info("Error Message : " + e.getMessage());
}
CreateRecurringPaymentsProfileResponseType createRecurringPaymentsProfileResponse = null;
try {
// ## Making API call
// Invoke the appropriate method corresponding to API in service
// wrapper object
createRecurringPaymentsProfileResponse = service
.createRecurringPaymentsProfile(createRecurringPaymentsProfileReq);
} catch (Exception e) {
LOGGER.info("Error Message : " + e.getMessage());
}
String ProfileID = "";
// ## Accessing response parameters
// You can access the response parameters using getter methods in
// response object as shown below
// ### Success values
if (createRecurringPaymentsProfileResponse.getAck().getValue()
.equalsIgnoreCase("success")) {
// A unique identifier for future reference to the details of
// this recurring payment.
ProfileID = createRecurringPaymentsProfileResponse
.getCreateRecurringPaymentsProfileResponseDetails()
.getProfileID();
LOGGER.info("Profile ID:"+ProfileID);
//mes = "approved";
}
// ### Error Values
// Access error values from error list using getter methods
else {
List<ErrorType> errorList = createRecurringPaymentsProfileResponse
.getErrors();
LOGGER.info("API Error Message : "
+ errorList.get(0).getLongMessage());
//mes = "error";
}
I hope this will helps you...
I'm fresh to SOAP in Java. I would like to create a client that generates a similar envelope to this:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2009/02/ws-tra/Create</a:Action>
<h:ChannelIdentifier xmlns:h="http://my-web-site.org/my-trans/identifiers/1.0/" xmlns="http://my-web-site.org/my-trans/identifiers/1.0/">4</h:ChannelIdentifier>
<h:DocumentIdentifier xmlns:h="http://my-web-site.org/my-trans/identifiers/1.0/" xmlns="http://my-web-site.org/my-trans/identifiers/1.0/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" scheme="">XXXXXX</h:DocumentIdentifier>
<h:MessageIdentifier xmlns:h="http://my-web-site.org/my-trans/identifiers/1.0/" xmlns="http://my-web-site.org/my-trans/identifiers/1.0/">d8c314a3-6add-474c-871a-e0872612beeb</h:MessageIdentifier>
<a:MessageID>urn:uuid:856e3d41-92ef-4332-8a36-82d98b436fb4</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://XXX.com/AP1/ResourceService.svc</a:To>
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Create xmlns="http://www.w3.org/2009/02/ws-tra">
<message xmlns=""><AccessPoint.BO.Document><![CDATA[Dummy Content]]></AccessPoint.BO.Document></message>
</Create>
</s:Body>
</s:Envelope>
The main challenge here is, how to generate these specific namespaces like a:Action or s:Header. Also how to add both xmlns and xml attributes in each one. I could hard code this but is there any standard to do this?
I prefer using javax.xml.soap.* but if there are better library, please let me know.
Use this draft (this requires more debugging):
SOAPMessage soap = MessageFactory.newInstance().createMessage();
SOAPEnvelope envelope = soap.getSOAPPart().getEnvelope();
envelope.addAttribute(new QName("xmlns:s"), "http://schemas.xmlsoap.org/soap/envelope/");
envelope.addAttribute(new QName("xmlns:a"), "http://www.w3.org/2005/08/addressing");
SOAPHeader header = soap.getSOAPHeader();
header.addAttribute(new QName("xmlns:xsd"), "http://www.w3.org/2001/XMLSchema");
header.addAttribute(new QName("xmlns:xsi"), "http://www.w3.org/2001/XMLSchema-instance");
SOAPElement actionElement = header.addChildElement("a:Action");
actionElement.addAttribute(new QName("s:mustUnderstand"), "1");
actionElement.addTextNode("http://www.w3.org/2009/02/ws-tra/Create");
SOAPElement channelIdentifierElement = header.addChildElement("h:ChannelIdentifier");
channelIdentifierElement.addAttribute(new QName("xmlns:h"), "http://my-web-site.org/my-trans/identifiers/1.0/");
channelIdentifierElement.addAttribute(new QName("xmlns"), "http://my-web-site.org/my-trans/identifiers/1.0/");
channelIdentifierElement.addTextNode("4");
SOAPElement documentIdentifierElement = header.addChildElement("h:DocumentIdentifier");
documentIdentifierElement.addAttribute(new QName("xmlns:h"), "http://my-web-site.org/my-trans/identifiers/1.0/");
documentIdentifierElement.addAttribute(new QName("xmlns"), "http://my-web-site.org/my-trans/identifiers/1.0/");
documentIdentifierElement.addAttribute(new QName("xmlns:xsd"), "http://www.w3.org/2001/XMLSchema");
documentIdentifierElement.addAttribute(new QName("xmlns:xsi"), "http://www.w3.org/2001/XMLSchema-instance");
documentIdentifierElement.addAttribute(new QName("scheme"), "");
documentIdentifierElement.addTextNode("XXXXXX");
SOAPElement messageIdentifierElement = header.addChildElement("h:MessageIdentifier");
messageIdentifierElement.addAttribute(new QName("xmlns:h"), "http://my-web-site.org/my-trans/identifiers/1.0/");
messageIdentifierElement.addAttribute(new QName("xmlns"), "http://my-web-site.org/my-trans/identifiers/1.0/");
messageIdentifierElement.addTextNode("d8c314a3-6add-474c-871a-e0872612beeb");
SOAPElement messageIdElement = header.addChildElement("a:MessageID");
messageIdElement.addTextNode("urn:uuid:856e3d41-92ef-4332-8a36-82d98b436fb4");
SOAPElement replyToElement = header.addChildElement("a:ReplyTo");
SOAPElement addressElement = replyToElement.addChildElement("a:Address");
addressElement.addTextNode("http://www.w3.org/2005/08/addressing/anonymous");
SOAPElement aToElement = header.addChildElement("a:To");
aToElement.addAttribute(new QName("s:mustUnderstand"), "1");
aToElement.addTextNode("https://XXX.com/AP1/ResourceService.svc");
SOAPBody body = soap.getSOAPBody();
body.addAttribute(new QName("xmlns:xsd"), "http://www.w3.org/2001/XMLSchema");
body.addAttribute(new QName("xmlns:xsi"), "http://www.w3.org/2001/XMLSchema-instance");
SOAPElement createElement = body.addChildElement("Create");
createElement.addAttribute(new QName("xmlns"), "http://www.w3.org/2009/02/ws-tra");
SOAPElement messageElement = createElement.addChildElement("message");
messageElement.addAttribute(new QName("xmlns"), "");
messageElement.addTextNode("<AccessPoint.BO.Document><![CDATA[Dummy Content]]></AccessPoint.BO.Document>");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
soap.writeTo(outputStream);
System.out.println(new String(outputStream.toByteArray()));