Search in sources :

Example 26 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class ComplexClient method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);
    }
    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }
    System.out.println(wsdlURL);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
    Client client = factory.createClient(wsdlURL.toExternalForm(), SERVICE_NAME);
    ClientImpl clientImpl = (ClientImpl) client;
    Endpoint endpoint = clientImpl.getEndpoint();
    ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0);
    QName bindingName = new QName("http://Company.com/Application", "Company_ESB_Application_Biztalk_AgentDetails_4405_AgentDetails_PrtSoap");
    BindingInfo binding = serviceInfo.getBinding(bindingName);
    // {
    QName opName = new QName("http://Company.com/Application", "GetAgentDetails");
    BindingOperationInfo boi = binding.getOperation(opName);
    BindingMessageInfo inputMessageInfo = boi.getInput();
    List<MessagePartInfo> parts = inputMessageInfo.getMessageParts();
    // only one part.
    MessagePartInfo partInfo = parts.get(0);
    Class<?> partClass = partInfo.getTypeClass();
    // GetAgentDetails
    System.out.println(partClass.getCanonicalName());
    Object inputObject = partClass.newInstance();
    // Unfortunately, the slot inside of the part object is also called 'part'.
    // this is the descriptor for get/set part inside the GetAgentDetails class.
    PropertyDescriptor partPropertyDescriptor = new PropertyDescriptor("part", partClass);
    // This is the type of the class which really contains all the parameter information.
    // AgentWSRequest
    Class<?> partPropType = partPropertyDescriptor.getPropertyType();
    System.out.println(partPropType.getCanonicalName());
    Object inputPartObject = partPropType.newInstance();
    partPropertyDescriptor.getWriteMethod().invoke(inputObject, inputPartObject);
    PropertyDescriptor numberPropertyDescriptor = new PropertyDescriptor("agentNumber", partPropType);
    numberPropertyDescriptor.getWriteMethod().invoke(inputPartObject, Integer.valueOf(314159));
    Object[] result = client.invoke(opName, inputObject);
    Class<?> resultClass = result[0].getClass();
    // GetAgentDetailsResponse
    System.out.println(resultClass.getCanonicalName());
    PropertyDescriptor resultDescriptor = new PropertyDescriptor("agentWSResponse", resultClass);
    Object wsResponse = resultDescriptor.getReadMethod().invoke(result[0]);
    Class<?> wsResponseClass = wsResponse.getClass();
    System.out.println(wsResponseClass.getCanonicalName());
    PropertyDescriptor agentNameDescriptor = new PropertyDescriptor("agentName", wsResponseClass);
    String agentName = (String) agentNameDescriptor.getReadMethod().invoke(wsResponse);
    System.out.println("Agent name: " + agentName);
}
Also used : JaxWsDynamicClientFactory(org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) PropertyDescriptor(java.beans.PropertyDescriptor) QName(javax.xml.namespace.QName) ClientImpl(org.apache.cxf.endpoint.ClientImpl) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) Client(org.apache.cxf.endpoint.Client) File(java.io.File)

Example 27 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class CorbaStreamFaultInInterceptor method getFaultInfo.

protected FaultInfo getFaultInfo(OperationInfo opInfo, QName faultName) {
    Iterator<FaultInfo> faults = opInfo.getFaults().iterator();
    while (faults.hasNext()) {
        FaultInfo fault = faults.next();
        MessagePartInfo partInfo = fault.getMessageParts().get(0);
        if (partInfo.isElement() && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
            return fault;
        } else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
            return fault;
        }
    }
    return null;
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 28 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class CorbaStreamFaultInInterceptor method createFaultDetail.

private void createFaultDetail(Document faultData, FaultInfo faultInfo, Fault faultEx) {
    MessagePartInfo partInfo = faultInfo.getMessageParts().get(0);
    QName partInfoName = partInfo.getElementQName();
    Document faultDoc = DOMUtils.getEmptyDocument();
    Element faultElement = faultDoc.createElement("detail");
    Element partElement = faultDoc.createElementNS(partInfoName.getNamespaceURI(), partInfoName.getLocalPart());
    Element faultDataElement = (Element) faultData.getFirstChild();
    Node node = faultDataElement.getFirstChild();
    while (node != null) {
        Node importedFaultData = faultDoc.importNode(node, true);
        partElement.appendChild(importedFaultData);
        node = node.getNextSibling();
    }
    faultElement.appendChild(partElement);
    faultEx.setDetail(faultElement);
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 29 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class CorbaStreamInInterceptor method getMessageParamQName.

protected QName getMessageParamQName(MessageInfo msgInfo, String paramName, int index) {
    QName paramQName = null;
    MessagePartInfo part = msgInfo.getMessageParts().get(index);
    if (part != null && part.isElement()) {
        paramQName = part.getElementQName();
    } else if (part != null) {
        paramQName = part.getName();
    }
    return paramQName;
}
Also used : QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 30 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class CorbaStreamFaultOutInterceptor method setUserExceptionFromFaultDetail.

protected void setUserExceptionFromFaultDetail(CorbaMessage message, org.w3c.dom.Element faultDetail, RaisesType exType, OperationInfo opInfo, DataWriter<XMLStreamWriter> writer, ServiceInfo service) throws Exception {
    QName exIdlType = exType.getException();
    QName elName = new QName("", exIdlType.getLocalPart());
    MessagePartInfo faultPart = getFaultMessagePartInfo(opInfo, elName);
    // faultDetailt.getFirstChild() skips the "detail" element
    Object fault = extractPartsInfoFromDetail((Element) faultDetail.getFirstChild(), exType);
    CorbaFaultStreamWriter faultWriter = new CorbaFaultStreamWriter(orb, exType, message.getCorbaTypeMap(), service);
    writer.write(fault, faultPart, faultWriter);
    CorbaObjectHandler[] objs = faultWriter.getCorbaObjects();
    CorbaStreamable streamable = message.createStreamableObject(objs[0], elName);
    message.setStreamableException(streamable);
}
Also used : CorbaStreamable(org.apache.cxf.binding.corba.CorbaStreamable) QName(javax.xml.namespace.QName) CorbaFaultStreamWriter(org.apache.cxf.binding.corba.runtime.CorbaFaultStreamWriter) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)163 QName (javax.xml.namespace.QName)99 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)46 MessageInfo (org.apache.cxf.service.model.MessageInfo)38 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)29 Fault (org.apache.cxf.interceptor.Fault)21 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)19 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)13 Method (java.lang.reflect.Method)12