Using JAX-WS to send SOAP request with headers - java

The request which I want to send is :-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://integration.standardandpoors.com/Schema/IDM">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-23762130">
<wsu:Created>2013-06-09T06:00:44.733Z</wsu:Created>
<wsu:Expires>2013-06-09T08:00:44.733Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" EncodingType="SSHA" ValueType="AccessManagerSSOSecurityToken" wsu:Id="OAMToken">TOKEN HARE</wsse:BinarySecurityToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<idm:findUserById>
<applicationName>APP ID</applicationName>
<userId>USER ID</userId>
</idm:findUserById>
</soapenv:Body>
</soapenv:Envelope>
My current java code is
public class WsClient{
public static void main(String[] args) throws Exception {
IdmService sis = new IdmService();
IdmWebServicePort si = sis.getIdmWebServiceImplPort();
WSBindingProvider bp = (WSBindingProvider)si;
Element node = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"> <wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Timestamp-23762130\"><wsu:Created>2013-06-09T06:00:44.733Z</wsu:Created> <wsu:Expires>2013-06-09T08:00:44.733Z</wsu:Expires></wsu:Timestamp><wsse:BinarySecurityToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" EncodingType=\"SSHA\" ValueType=\"AccessManagerSSOSecurityToken\" wsu:Id=\"OAMToken\">token here</wsse:BinarySecurityToken></wsse:Security>".getBytes())).getDocumentElement();
bp.setOutboundHeaders(
Headers.create(node)
);
//si.getSecurityChallengeQuestionsAndAnswersForUser("APP NAME", "USER ID");
User u=si.findUserById("MSA", "test100#sandp.com");
System.out.println(u.getFirstName());
}
}
error which I am getting is :-
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.xml.bind.api.JAXBRIContext.newInstance

Related

How do I call a request that has entity in it?

(1) The class I described below includes three strings and one entity.
(2) The text I sent as a call is as follows.
(3) But I'm making the mistake.
1:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {"tesisatKod", "islemGuid", "islemTutari", "islemTuru"})
#XmlRootElement(name = "secondStageRequest")
public class SecondStageRequest {
protected String tesisatKod;
protected String islemGuid;
// protected Date sorguSaatTarih;
protected String islemTutari;
protected IslemTuru islemTuru;
}
2:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xc="http://xml.cinigaz.com.tr">
<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>admin</wsse:Username>
<wsse:Password>pwd1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<xc:secondStageRequest>
<xc:tesisatKod>bbb</xc:tesisatKod>
<xc:islemGuid>bbb</xc:islemGuid>
<xc:islemTutari>bbb</xc:islemTutari>
<xc:islemTuru>
<xc:islemTuruId> 1</xc:islemTuruId>
<xc:islemTuruAdi> aaa</xc:islemTuruAdi>
</xc:islemTuru>
</xc:secondStageRequest>
</soapenv:Body>
</soapenv:Envelope>
3:
WARN 20148 --- [nio-9020-exec-2] s.w.s.s.e.i.PayloadValidatingInterceptor : XML validation error on request: cvc-type.3.1.2: Element 'xc:islemTuru' is a simple type, so it must have no element information item [children].

How to handle multiple SOAP requests in the same envelope using Java Web Service?

I currently have a web service with the method:
#Override
#WebResult(Name="OIPResponse")
public Map<String, Object> getOIP(#WebParam(name = "invoice") String invoiceNumber,#WebParam(name = "part") String partNumber)
The normal SOAP request I use to call it looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/">
<soapenv:Header/>
<soapenv:Body>
<oip:getOIP>
<invoice>41587182</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
</soapenv:Body>
</soapenv:Envelope>
and the response is something like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/">
<OIPResponse>
<entry>
<key>ERR_CODE</key>
</entry>
<entry>
<key>SELLING_OU</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">null</value>
</entry>
...
</OIPResponse>
</ns2:getOIPResponse>
</soap:Body>
</soap:Envelope>
I've tested this and it works fine. Now I am wondering if there is a way to include multiple requests in the same SOAP envelope like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/">
<soapenv:Header/>
<soapenv:Body>
<oip:getOIP>
<invoice>41587182</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587183</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587184</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587185</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
</soapenv:Body>
</soapenv:Envelope>
and get back something like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/">
<OIPResponse>
...
</OIPResponse>
<OIPResponse>
...
</OIPResponse>
<OIPResponse>
...
</OIPResponse>
...
</ns2:getOIPResponse>
</soap:Body>
</soap:Envelope>
Is there any way to do this?
I ended up creating a POJO called OIPRequest that contained the two parameters I need (invoice and part number) and a new method getOIPMultiple which takes an array of OIPRequests as an input parameter.
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class OIPRequest {
public String invoiceNumber, partNumber;
public OIPRequest(String invoice, String part) {
invoiceNumber = invoice;
partNumber = part;
}
public OIPRequest() {
invoiceNumber = "";
partNumber = "";
}
}
This makes the request look like this:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getMultipleOIP xmlns="http://oip.mycompany.com/">
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
</getMultipleOIP>
</Body>
</Envelope>

How to create SOAP request with CDATA

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>]]>

java paypal merchant sdk recurring payment invalid token

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...

SOAP request modification

I have a SOAP request like this, it's working fine:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://com/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<!--Optional:-->
<FromCurrency>?</FromCurrency>
<!--Optional:-->
<ToCurrency>?</ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
I was changing the request a litle bit to understand the concepts:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate xmlns="http://com/">>
<!--Optional:-->
<FromCurrency>?</FromCurrency>
<!--Optional:-->
<ToCurrency>?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
The second one is not working, throwing a wrong answer.
My service class is
package com;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
#WebService (targetNamespace="http://com/")
public class CurrencyConvertor
{
public String ConversionRate (#WebParam(name = "FromCurrency") String FromCurrency, #WebParam(name = "ToCurrency") String ToCurrency)
{
System.out.println("ST\n" + FromCurrency + "\n" + ToCurrency + "\nEnd" );
switch(FromCurrency+","+ToCurrency)
{
case "USD,INR":
return "58";
case "INR,USD":
return "0.017";
default:
return "XXX";
}
}
}
The second request always falling to default case, the thing is, the values are sending as null since I changed the name space. So my Web service should answer for the second request properly, what should cause the issue, how to rectify this.
your namespace is not correct even it looks well.
I have to change com to com.example, because it is not possible to post answer with link to com only.
tns=http://com.example/ is defined in
the WebService, not for the webmethod. Change your method declaration to
public String ConversionRate (
#WebParam(name = "FromCurrency", tagetNamespace = "http://com.example/") String FromCurrency,
#WebParam(name = "ToCurrency", tagetNamespace = "http://com.example/") String ToCurrency) {
...
}
Even I'm not definitely sure if the XML has valid format
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate xmlns="http://com.example/">
<FromCurrency>?</FromCurrency>
<ToCurrency>?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
or namespace is required just for parameters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<ConversionRate>
<FromCurrency xmlns="http://com.example/">?</FromCurrency>
<ToCurrency xmlns="http://com.example/">?</ToCurrency>
</ConversionRate>
</soapenv:Body>
</soapenv:Envelope>

Categories

Resources