dimanche 19 avril 2015

Calling SOAP service from Java - Object not set error

I am trying to consume a SOAP service from Java (eclipse). I have generated the Java class using the CFX2 apache and I am trying to consume/create a web service client.


Here is my code



package com.webClient;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

import com.sap.xi.ap.common.gdt.Log;
import com.sap.xi.ap.common.gdt.LogItem;

public class Main {

private static final String WS_URL = "file:/C:/Users/143517/workspace/Consumeweb/WebContent/Y2W9CM47Y_ManageOrderCreationIn.wsdl";

public static void main (String args[]) throws RemoteException, StandardFaultMessage
{
URL url;
Service serv = null;
try {

url = new URL(WS_URL);
javax.xml.namespace.QName qname = new javax.xml.namespace.QName("http://ift.tt/1IsWVx4","service");
serv = Service.create(url,qname);
//com.webClient.Service service = new com.webClient.Service();
serv = new com.webClient.Service();
//serv.setExecutor(service.getExecutor());;

} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Y2W9CM47YManageOrderCreationIn implClass = serv.getPort(Y2W9CM47YManageOrderCreationIn.class);
BindingProvider provider = (BindingProvider) implClass;
java.util.Map<String, Object> req_ctx = provider.getRequestContext();

req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
Map<String, List<String>> headers = new HashMap<String, List<String>>();

headers.put("Username", Collections.singletonList("XXXX"));
headers.put("Password", Collections.singletonList("XXXXXX"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);

OrderCreationpullOrderpullOrderRequest request = new OrderCreationpullOrderpullOrderRequest();
request.orderID = "1";
OrderCreationpullOrderpullOrderRequestSyncMessage msg = new OrderCreationpullOrderpullOrderRequestSyncMessage();
msg.setOrderCreation(request);
OrderCreationpullOrderpullOrderConfirmationMessageSync response = implClass.pullOrder(msg);
Log log = response.getLog();
String note;
List<LogItem> logItem = log.getItem();
for (LogItem logItem2 : logItem) {
note = logItem2.getNote();
System.out.println(note);
}

}

}


I understand that the CFX 2 builds the service class by itself. I need to call the operation and also pass the authentication by getting the requestContext and adding the parameters in header.


When I run this, I am getting an error with the stack as shown below:



Apr 19, 2015 8:38:43 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL INFO: Creating Service {http://ift.tt/1Q5CQSU}service from WSDL: file:/C:/Users/143517/workspace/Consumeweb/WebContent/Y2W9CM47Y_ManageOrderCreationIn.wsdl Apr 19, 2015 8:38:48 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL INFO: Creating Service {http://ift.tt/1Q5CQSU}service from WSDL: file:/C:/Users/143517/workspace/Consumeweb/WebContent/Y2W9CM47Y_ManageOrderCreationIn.wsdl Apr 19, 2015 8:39:01 PM com.sun.corba.se.impl.resolver.INSURLOperationImpl operate WARNING: "IOP00100007: (BAD_PARAM) string_to_object conversion failed due to bad scheme name" org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 7 completed: No at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.resolver.INSURLOperationImpl.operate(Unknown Source) at com.sun.corba.se.impl.orb.ORBImpl.string_to_object(Unknown Source) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReferenceFromFile(CorbaUtils.java:541) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReference(CorbaUtils.java:506) at org.apache.cxf.binding.corba.CorbaConduit.prepare(CorbaConduit.java:121) at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138) at com.sun.proxy.$Proxy38.pullOrder(Unknown Source) at com.webClient.Main.main(Main.java:62)


Apr 19, 2015 8:39:01 PM org.apache.cxf.binding.corba.CorbaConduit prepare SEVERE: Could not resolve target object Apr 19, 2015 8:39:01 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging WARNING: Interceptor for {http://ift.tt/1Q5CQSU}service#{http://ift.tt/1Q5CQSU}pullOrder has thrown exception, unwinding now org.apache.cxf.binding.corba.CorbaBindingException: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 7 completed: No at org.apache.cxf.binding.corba.CorbaConduit.prepare(CorbaConduit.java:133) at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138) at com.sun.proxy.$Proxy38.pullOrder(Unknown Source) at com.webClient.Main.main(Main.java:62) Caused by: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 7 completed: No at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.resolver.INSURLOperationImpl.operate(Unknown Source) at com.sun.corba.se.impl.orb.ORBImpl.string_to_object(Unknown Source) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReferenceFromFile(CorbaUtils.java:541) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReference(CorbaUtils.java:506) at org.apache.cxf.binding.corba.CorbaConduit.prepare(CorbaConduit.java:121) ... 10 more


Exception in thread "main" org.apache.cxf.binding.corba.CorbaBindingException: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 7 completed: No at org.apache.cxf.binding.corba.CorbaConduit.prepare(CorbaConduit.java:133) at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138) at com.sun.proxy.$Proxy38.pullOrder(Unknown Source) at com.webClient.Main.main(Main.java:62) Caused by: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 7 completed: No at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.logging.OMGSystemException.soBadSchemeName(Unknown Source) at com.sun.corba.se.impl.resolver.INSURLOperationImpl.operate(Unknown Source) at com.sun.corba.se.impl.orb.ORBImpl.string_to_object(Unknown Source) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReferenceFromFile(CorbaUtils.java:541) at org.apache.cxf.binding.corba.utils.CorbaUtils.importObjectReference(CorbaUtils.java:506) at org.apache.cxf.binding.corba.CorbaConduit.prepare(CorbaConduit.java:121) ... 10 more



I also did some research and found that there might be problem with CLASSPATH? Also, there might be problem with the service that I am defining.


Aucun commentaire:

Enregistrer un commentaire