I want to use paypal as a payment process in my application.
At paypal they have shown many ways as using REST API, classic api, and also using SOAP API.
I am trying to use SOAP client by following way.
1.I am trying to create a SOAP web service client using paypal's provided wsdl file. But it's giving me error while creating client as ' unable to retieve that url',though it creates client files.
2.Created object for proxyClass, as proxy class contains all required methods like getAuthDetails,setExpressCheckout,setEndPoint etc.
3.So these method contains parameters like DetailLevelCodeType[]detailLevel,MessageElement[]_any. so what will be the value for it ?
4.As per my understanding if I am performing any operation on payapal, it should ask me first authentication parameters like username,secret, token, password of my account. When it comes to paypal using rest api, I am aware about getting access token by providing user credentials.
So in soap web service client how to get that first? I didin't get any method available here for that.
But I have got one way to perform authorization from this link. security credentials .
So I followed these steps, now I have my username,password.
In next topic they are explaining , your SOAP client must set the Username, Password elements to pass an API username/password combination in the SOAP request header.
So I am trying in this way to add username,password in request header reference.
This process includes marshalling.
//packages used so far
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.rpc.ServiceException;
import javax.xml.soap.SOAPHeader;
public static void main(String[] args) {
// TODO Auto-generated method stub
PayPalAPIAAInterfaceProxy proxy=new PayPalAPIAAInterfaceProxy();
// proxy.setEndpoint("");
// following class is generated by wsdl2java utility Service class
final PayPalAPIInterfaceService payPalService = new PayPalAPIInterfaceServiceLocator();
PayPalAPIAAInterface expressCheckoutPort;
try {
expressCheckoutPort = payPalService.getPayPalAPIAA();
final Binding binding = ((BindingProvider) expressCheckoutPort).getBinding();
List<Handler> handlersList = new ArrayList<Handler>();
// now, adding instance of Handler to handlersList which should do our job:
// creating header instance
final CustomSecurityHeaderType headerObj = new CustomSecurityHeaderType();
final UserIdPasswordType credentials = new UserIdPasswordType();
credentials.setUsername("username");
credentials.setPassword("password");
credentials.setSignature("signature");
headerObj.setCredentials(credentials);
// bookmark #1 - please read explanation after code
final ObjectFactory objectFactory = new ObjectFactory();
// creating JAXBElement from headerObj
final JAXBElement<CustomSecurityHeaderType> requesterCredentials = objectFactory.createRequesterCredentials(headerObj);
handlersList.add(new SOAPHandler<SOAPMessageContext>() {
@Override
public boolean handleMessage(final SOAPMessageContext context) {
try {
// checking whether handled message is outbound one as per Martin Strauss answer
final Boolean outbound = (Boolean) context.get("javax.xml.ws.handler.message.outbound");
if (outbound != null && outbound) {
// obtaining marshaller which should marshal instance to xml
final Marshaller marshaller = JAXBContext.newInstance(CustomSecurityHeaderType.class).createMarshaller();
// adding header because otherwise it's null
final SOAPHeader soapHeader = context.getMessage().getSOAPPart().getEnvelope().addHeader();
// marshalling instance (appending) to SOAP header's xml node
marshaller.marshal(requesterCredentials, soapHeader);
}
} catch (final Exception e) {
throw new RuntimeException(e);
}
return true;
}
// ... default implementations of other methods go here
});
// as per Jean-Bernard Pellerin's comment setting handlerChain list here, after all handlers were added to list
binding.setHandlerChain(handlersList);
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
But I observed a file is missing named ObjectFactory
.
I have included Merchant api sdk's jar file also. And in my web service client this file is not present.
So can anybody guide me in this context that why file is not getting created when creating client from wsdl file ?
I have also tried to create web service client using wsdl to java plugin, but it is giving me error as
wsdlexception faultcode other_error ,it's also saying FileNotFoundException
, unable to find https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl/eBLBaseComponents.xsd