Search in sources :

Example 1 with Call

use of org.apache.axis.client.Call in project Lucee by lucee.

the class AxisUtil method getSOAPResponse.

public static Node getSOAPResponse(WSClient client) throws Exception {
    Call call = client.getLastCall();
    if (call == null)
        throw new AxisFault("web service was not invoked yet");
    SOAPEnvelope env = call.getResponseMessage().getSOAPEnvelope();
    return XMLCaster.toXMLStruct(env.getAsDocument(), true);
}
Also used : AxisFault(org.apache.axis.AxisFault) Call(org.apache.axis.client.Call) SOAPEnvelope(org.apache.axis.message.SOAPEnvelope)

Example 2 with Call

use of org.apache.axis.client.Call in project Lucee by lucee.

the class Axis1Client method _call.

private Object _call(PageContext pc, Config secondChanceConfig, String methodName, Struct namedArguments, Object[] arguments) throws PageException, ServiceException, RemoteException {
    ApplicationContextSupport acs = (ApplicationContextSupport) pc.getApplicationContext();
    javax.wsdl.Service service = getWSDLService();
    Service axisService = new Service(parser, service.getQName());
    axisService.setMaintainSession(acs.getWSMaintainSession());
    TypeMappingUtil.registerDefaults(axisService.getTypeMappingRegistry());
    Port port = WSUtil.getSoapPort(service);
    Binding binding = port.getBinding();
    SymbolTable symbolTable = parser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    // get matching operation/method
    Iterator<Entry<Operation, Parameters>> itr = bEntry.getParameters().entrySet().iterator();
    Operation operation = null;
    Entry<Operation, Parameters> e;
    Parameters parameters = null;
    while (itr.hasNext()) {
        e = itr.next();
        if (e.getKey().getName().equalsIgnoreCase(methodName)) {
            operation = e.getKey();
            parameters = e.getValue();
            break;
        }
    }
    // no operation found!
    if (operation == null || parameters == null) {
        // get array of existing methods
        Set<Operation> set = bEntry.getParameters().keySet();
        Iterator<Operation> it = set.iterator();
        Collection.Key[] keys = new Collection.Key[set.size()];
        int index = 0;
        while (it.hasNext()) {
            keys[index++] = KeyImpl.init(it.next().getName());
        }
        throw new RPCException(ExceptionUtil.similarKeyMessage(keys, methodName, "method/operation", "methods/operations", null, true) + " Webservice: " + wsdlUrl);
    }
    org.apache.axis.client.Call call = (Call) axisService.createCall(QName.valueOf(port.getName()), QName.valueOf(operation.getName()));
    if (!StringUtil.isEmpty(username, true)) {
        call.setUsername(username);
        call.setPassword(password);
    }
    org.apache.axis.encoding.TypeMapping tm = call.getTypeMapping();
    Vector<String> inNames = new Vector<String>();
    Vector<Parameter> inTypes = new Vector<Parameter>();
    Vector<String> outNames = new Vector<String>();
    Vector<Parameter> outTypes = new Vector<Parameter>();
    Parameter p = null;
    for (int j = 0; j < parameters.list.size(); j++) {
        p = (Parameter) parameters.list.get(j);
        map(pc, symbolTable, secondChanceConfig, tm, p.getType());
        switch(p.getMode()) {
            case Parameter.IN:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                break;
            case Parameter.OUT:
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
            case Parameter.INOUT:
                inNames.add(p.getQName().getLocalPart());
                inTypes.add(p);
                outNames.add(p.getQName().getLocalPart());
                outTypes.add(p);
                break;
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        QName rtnQName = parameters.returnParam.getQName();
        // TypeEntry rtnType = parameters.returnParam.getType();
        map(pc, symbolTable, secondChanceConfig, tm, parameters.returnParam.getType());
        outNames.add(rtnQName.getLocalPart());
        outTypes.add(parameters.returnParam);
    }
    // get timezone
    TimeZone tz;
    if (pc == null)
        tz = ThreadLocalPageContext.getTimeZone(secondChanceConfig);
    else
        tz = ThreadLocalPageContext.getTimeZone(pc);
    // check arguments
    Object[] inputs = new Object[inNames.size()];
    if (arguments != null) {
        if (inNames.size() != arguments.length)
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + arguments.length + " instead of " + inNames.size() + ")");
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            inputs[pos] = getArgumentData(tm, tz, p, arguments[pos]);
        }
    } else {
        UDFUtil.argumentCollection(namedArguments);
        if (inNames.size() != namedArguments.size())
            throw new RPCException("Invalid arguments count for operation " + methodName + " (" + namedArguments.size() + " instead of " + inNames.size() + ")");
        Object arg;
        for (int pos = 0; pos < inNames.size(); pos++) {
            p = inTypes.get(pos);
            arg = namedArguments.get(KeyImpl.init(p.getName()), null);
            if (arg == null) {
                throw new RPCException("Invalid arguments for operation " + methodName, getErrorDetailForArguments(inNames.toArray(new String[inNames.size()]), CollectionUtil.keysAsString(namedArguments)));
            }
            inputs[pos] = getArgumentData(tm, tz, p, arg);
        }
    }
    Object ret = null;
    // add header
    if (headers != null && !headers.isEmpty()) {
        Iterator<SOAPHeaderElement> it = headers.iterator();
        while (it.hasNext()) {
            call.addHeader(it.next());
        }
    }
    try {
        ret = invoke(call, inputs);
    } catch (AxisFault af) {
        boolean rethrow = true;
        Throwable cause = af.getCause();
        if (cause != null) {
            /*
        		// first check if that missing type is around
        		String[] notFound=new String[]{"could not find deserializer for type","No deserializer for"};
        		int index;
        		if(msg!=null)for(int i=0; i<notFound.length;i++) {
        			if((index=msg.indexOf(notFound[i]))==-1)continue;;
        			
        			String raw=msg.substring(index+notFound[i].length()+1).trim();
        			QName qn = QName.valueOf(raw);
        			print.e(qn.getLocalPart());
        			print.e(qn.getNamespaceURI());
        			Type type = symbolTable.getType(qn);
        			if(type!=null) {
        				map(pc,secondChanceConfig,call.getTypeMapping(),type);
        				ret = invoke(call,inputs);
        				rethrow=false;
        			}
        		}*/
            // get the missing types from the SOAP Body, if possible
            String msg = cause.getMessage();
            // if(StringUtil.indexOfIgnoreCase(msg, "deserializer")!=-1) {
            try {
                InputSource is = new InputSource(new StringReader(call.getResponseMessage().getSOAPPartAsString()));
                Document doc = XMLUtil.parse(is, null, false);
                Element body = XMLUtil.getChildWithName("soapenv:Body", doc.getDocumentElement());
                Vector types = SOAPUtil.getTypes(body, symbolTable);
                map(pc, symbolTable, secondChanceConfig, (org.apache.axis.encoding.TypeMapping) (axisService.getTypeMappingRegistry().getDefaultTypeMapping()), types);
                ret = invoke(call, inputs);
                rethrow = false;
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        // }
        }
        if (rethrow)
            throw af;
    }
    last = call;
    if (outNames.size() <= 1)
        return AxisCaster.toLuceeType(null, ret);
    // getParamData((org.apache.axis.client.Call)call,parameters.returnParam,ret);
    Map outputs = call.getOutputParams();
    Struct sct = new StructImpl();
    for (int pos = 0; pos < outNames.size(); pos++) {
        String name = outNames.get(pos);
        // print.ln(name);
        Object value = outputs.get(name);
        if (value == null && pos == 0) {
            sct.setEL(name, AxisCaster.toLuceeType(null, ret));
        } else {
            sct.setEL(name, AxisCaster.toLuceeType(null, value));
        }
    }
    return sct;
}
Also used : AxisFault(org.apache.axis.AxisFault) InputSource(org.xml.sax.InputSource) Port(javax.wsdl.Port) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) Element(org.w3c.dom.Element) Call(org.apache.axis.client.Call) Operation(javax.wsdl.Operation) Document(org.w3c.dom.Document) Struct(lucee.runtime.type.Struct) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Entry(java.util.Map.Entry) SymTabEntry(org.apache.axis.wsdl.symbolTable.SymTabEntry) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry) ServiceEntry(org.apache.axis.wsdl.symbolTable.ServiceEntry) RPCException(lucee.runtime.net.rpc.RPCException) StringReader(java.io.StringReader) Vector(java.util.Vector) Binding(javax.wsdl.Binding) SOAPHeaderElement(org.apache.axis.message.SOAPHeaderElement) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) Call(org.apache.axis.client.Call) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) QName(javax.xml.namespace.QName) Service(org.apache.axis.client.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) TimeZone(java.util.TimeZone) StructImpl(lucee.runtime.type.StructImpl) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) TypeMapping(javax.xml.rpc.encoding.TypeMapping) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Example 3 with Call

use of org.apache.axis.client.Call in project portal by ixinportal.

the class BaiWangServiceImplTest method baiwangdanjichaxunTest.

@Test
public void baiwangdanjichaxunTest() {
    StringBuilder builder = new StringBuilder();
    String url = "http://120.26.131.180:19900/fpfw/kpbusiness";
    /**
     *<?xml version="1.0" encoding="utf-8"?>
     *<business comment="查询申请结果" id="CXSQJG">
     *    <head>
     *        <login_name>用户名</login_name>
     *        <passwd>密码</passwd>
     *        <skpbh>税控盘编号,唯一</skpbh>
     *        <nsrsbh>纳税人识别号,唯一</nsrsbh>
     *    </head>
     *</business>
     */
    builder.append("<?xml version='1.0' encoding='utf-8'?>");
    builder.append("<business comment='查询申请结果' id='CXSQJG'>");
    builder.append("head>");
    builder.append("<login_name>用户名</login_name>");
    builder.append("<passwd>密码</passwd>");
    builder.append("<skpbh>税控盘编号,唯一</skpbh>");
    builder.append("<nsrsbh>纳税人识别号,唯一</nsrsbh>");
    builder.append("</head>");
    builder.append("</business>");
    org.apache.axis.client.Service s = new org.apache.axis.client.Service();
    Call call;
    try {
        call = (Call) s.createCall();
        call.setTargetEndpointAddress(new URL(url));
        call.setOperation("doService");
        Object[] fn01 = { builder.toString() };
        String result = (String) call.invoke(fn01);
        System.out.println(result);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
/**
 *		 返回报文:
 *<?xml version="1.0" encoding="utf-8"?>
 *<business id="ZCSQ" version='1.0'>
 *<body>
 *<returncode>0</returncode>
 *<returnmsg>成功</returnmsg>
 *</body>
 *</business>
 */
}
Also used : Call(org.apache.axis.client.Call) URL(java.net.URL) ServiceException(javax.xml.rpc.ServiceException) AbstractTest(com.itrus.portal.abstracttest.test.AbstractTest) Test(org.junit.Test)

Example 4 with Call

use of org.apache.axis.client.Call in project tomee by apache.

the class GenericServiceEndpoint method createCall.

Call createCall() throws java.rmi.RemoteException {
    try {
        org.apache.axis.client.Call _call = (org.apache.axis.client.Call) service.createCall();
        if (super.maintainSessionSet) {
            _call.setMaintainSession(super.maintainSession);
        }
        if (super.cachedUsername != null) {
            _call.setUsername(super.cachedUsername);
        }
        if (super.cachedPassword != null) {
            _call.setPassword(super.cachedPassword);
        }
        if (super.cachedEndpoint != null) {
            _call.setTargetEndpointAddress(super.cachedEndpoint);
        }
        if (super.cachedTimeout != null) {
            _call.setTimeout(super.cachedTimeout);
        }
        if (super.cachedPortName != null) {
            _call.setPortName(super.cachedPortName);
        }
        java.util.Enumeration keys = super.cachedProperties.keys();
        while (keys.hasMoreElements()) {
            java.lang.String key = (java.lang.String) keys.nextElement();
            _call.setProperty(key, super.cachedProperties.get(key));
        }
        // }
        return _call;
    } catch (java.lang.Throwable t) {
        throw new org.apache.axis.AxisFault("Failure trying to get the Call object", t);
    }
}
Also used : Call(org.apache.axis.client.Call) Call(org.apache.axis.client.Call) AxisFault(org.apache.axis.AxisFault)

Example 5 with Call

use of org.apache.axis.client.Call in project tomee by apache.

the class ServiceEndpointMethodInterceptor method doIntercept.

private Object doIntercept(Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
    int index = methodProxy.getSuperIndex();
    OperationInfo operationInfo = operations[index];
    if (operationInfo == null) {
        throw new ServerRuntimeException("Operation not mapped: " + method.getName() + " index: " + index + "\n OperationInfos: " + Arrays.asList(operations));
    }
    stub.checkCachedEndpoint();
    Call call = stub.createCall();
    operationInfo.prepareCall(call);
    stub.setUpCall(call);
    if (credentialsName != null) {
        throw new UnsupportedOperationException("Client side auth is not implementd");
    // Subject subject = ContextManager.getNextCaller();
    // if (subject == null) {
    // throw new IllegalStateException("Subject missing but authentication turned on");
    // } else {
    // Set creds = subject.getPrivateCredentials(NamedUsernamePasswordCredential.class);
    // boolean found = false;
    // for (Iterator iterator = creds.iterator(); iterator.hasNext();) {
    // NamedUsernamePasswordCredential namedUsernamePasswordCredential = (NamedUsernamePasswordCredential) iterator.next();
    // if (credentialsName.equals(namedUsernamePasswordCredential.getName())) {
    // call.setUsername(namedUsernamePasswordCredential.getUsername());
    // call.setPassword(new String(namedUsernamePasswordCredential.getPassword()));
    // found = true;
    // break;
    // }
    // }
    // if (!found) {
    // throw new IllegalStateException("no NamedUsernamePasswordCredential found for name " + credentialsName);
    // }
    // }
    }
    Object response = null;
    List parameterDescs = operationInfo.getOperationDesc().getParameters();
    Object[] unwrapped = extractFromHolders(objects, parameterDescs, operationInfo.getOperationDesc().getNumInParams());
    if (operationInfo.getOperationDesc().getMep() == OperationType.REQUEST_RESPONSE) {
        try {
            response = call.invoke(unwrapped);
        } catch (RemoteException e) {
            throw operationInfo.unwrapFault(e);
        }
        if (response instanceof RemoteException) {
            throw operationInfo.unwrapFault((RemoteException) response);
        } else {
            stub.extractAttachments(call);
            Map outputParameters = call.getOutputParams();
            putInHolders(outputParameters, objects, parameterDescs);
            Class returnType = operationInfo.getOperationDesc().getReturnClass();
            // return type should never be null... but we are not objecting if wsdl-return-value-mapping is not set.
            if (response == null || returnType == null || returnType.isAssignableFrom(response.getClass())) {
                return response;
            } else {
                return JavaUtils.convert(response, returnType);
            }
        }
    } else if (operationInfo.getOperationDesc().getMep() == OperationType.ONE_WAY) {
        // one way
        call.invokeOneWay(unwrapped);
        return null;
    } else {
        throw new ServerRuntimeException("Invalid messaging style: " + operationInfo.getOperationDesc().getMep());
    }
}
Also used : Call(org.apache.axis.client.Call) List(java.util.List) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) RemoteException(java.rmi.RemoteException) Map(java.util.Map)

Aggregations

Call (org.apache.axis.client.Call)11 URL (java.net.URL)5 Map (java.util.Map)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 SSLSession (javax.net.ssl.SSLSession)4 Service (org.apache.axis.client.Service)4 BASE64Encoder (sun.misc.BASE64Encoder)4 HashMap (java.util.HashMap)3 QName (javax.xml.namespace.QName)3 AxisFault (org.apache.axis.AxisFault)3 Test (org.junit.Test)3 BASE64Decoder (sun.misc.BASE64Decoder)3 Date (java.util.Date)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)2 Document (org.w3c.dom.Document)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AbstractTest (com.itrus.portal.abstracttest.test.AbstractTest)1 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)1 ApplicationInfoExample (com.itrus.portal.db.ApplicationInfoExample)1