Search in sources :

Example 21 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo 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 22 with ServiceInfo

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

the class CorbaStreamInInterceptor method handleRequest.

private void handleRequest(Message msg) {
    ORB orb;
    ServiceInfo service;
    CorbaDestination destination;
    if (msg.getDestination() != null) {
        destination = (CorbaDestination) msg.getDestination();
    } else {
        destination = (CorbaDestination) msg.getExchange().getDestination();
    }
    service = destination.getBindingInfo().getService();
    CorbaMessage message = (CorbaMessage) msg;
    Exchange exchange = message.getExchange();
    CorbaTypeMap typeMap = message.getCorbaTypeMap();
    BindingInfo bInfo = destination.getBindingInfo();
    InterfaceInfo info = bInfo.getInterface();
    String opName = exchange.get(String.class);
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();
    OperationType opType = null;
    BindingOperationInfo bopInfo = null;
    QName opQName = null;
    while (i.hasNext()) {
        bopInfo = i.next();
        if (bopInfo.getName().getLocalPart().equals(opName)) {
            opType = bopInfo.getExtensor(OperationType.class);
            opQName = bopInfo.getName();
            break;
        }
    }
    if (opType == null) {
        throw new RuntimeException("Couldn't find the binding operation for " + opName);
    }
    orb = exchange.get(ORB.class);
    ServerRequest request = exchange.get(ServerRequest.class);
    NVList list = prepareArguments(message, info, opType, opQName, typeMap, destination, service);
    request.arguments(list);
    message.setList(list);
    HandlerIterator paramIterator = new HandlerIterator(message, true);
    final CorbaTypeEventProducer eventProducer;
    BindingMessageInfo msgInfo = bopInfo.getInput();
    boolean wrap = false;
    if (bopInfo.isUnwrappedCapable()) {
        wrap = true;
    }
    if (wrap) {
        // wrapper element around our args
        QName wrapperElementQName = msgInfo.getMessageInfo().getName();
        eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName, paramIterator, service, orb);
    } else {
        eventProducer = new ParameterEventProducer(paramIterator, service, orb);
    }
    CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
    message.setContent(XMLStreamReader.class, reader);
}
Also used : CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) WrappedParameterSequenceEventProducer(org.apache.cxf.binding.corba.types.WrappedParameterSequenceEventProducer) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) HandlerIterator(org.apache.cxf.binding.corba.types.HandlerIterator) CorbaStreamReader(org.apache.cxf.binding.corba.runtime.CorbaStreamReader) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Exchange(org.apache.cxf.message.Exchange) ParameterEventProducer(org.apache.cxf.binding.corba.types.ParameterEventProducer) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) CorbaTypeEventProducer(org.apache.cxf.binding.corba.types.CorbaTypeEventProducer) ServerRequest(org.omg.CORBA.ServerRequest) NVList(org.omg.CORBA.NVList) ORB(org.omg.CORBA.ORB)

Example 23 with ServiceInfo

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

the class CorbaConduit method buildRequest.

public void buildRequest(CorbaMessage message, OperationType opType) throws Exception {
    ServiceInfo service = message.getExchange().getEndpoint().getEndpointInfo().getService();
    NVList nvlist = getArguments(message);
    NamedValue ret = getReturn(message);
    Map<TypeCode, RaisesType> exceptions = getOperationExceptions(opType, typeMap);
    ExceptionList exList = getExceptionList(exceptions, message, opType);
    Request request = getRequest(message, opType.getName(), nvlist, ret, exList);
    if (request == null) {
        throw new CorbaBindingException("Couldn't build the corba request");
    }
    Exception ex;
    try {
        request.invoke();
        ex = request.env().exception();
    } catch (SystemException sysex) {
        ex = sysex;
    }
    if (ex != null) {
        if (ex instanceof SystemException) {
            message.setContent(Exception.class, new Fault(ex));
            message.setSystemException((SystemException) ex);
            return;
        }
        if (ex instanceof UnknownUserException) {
            UnknownUserException userEx = (UnknownUserException) ex;
            Any except = userEx.except;
            RaisesType raises = exceptions.get(except.type());
            if (raises == null) {
                throw new CorbaBindingException("Couldn't find the exception type code to unmarshall");
            }
            QName elName = new QName("", raises.getException().getLocalPart());
            CorbaObjectHandler handler = CorbaHandlerUtils.initializeObjectHandler(orb, elName, raises.getException(), typeMap, service);
            CorbaStreamable exStreamable = message.createStreamableObject(handler, elName);
            exStreamable._read(except.create_input_stream());
            message.setStreamableException(exStreamable);
            message.setContent(Exception.class, new Fault(userEx));
        } else {
            message.setContent(Exception.class, new Fault(ex));
        }
    }
}
Also used : TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Request(org.omg.CORBA.Request) UnknownUserException(org.omg.CORBA.UnknownUserException) ExceptionList(org.omg.CORBA.ExceptionList) NamedValue(org.omg.CORBA.NamedValue) Fault(org.apache.cxf.interceptor.Fault) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) UnknownUserException(org.omg.CORBA.UnknownUserException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) SystemException(org.omg.CORBA.SystemException) CorbaObjectHandler(org.apache.cxf.binding.corba.types.CorbaObjectHandler) NVList(org.omg.CORBA.NVList)

Example 24 with ServiceInfo

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

the class ColocOutInterceptorTest method verifyIsColocatedWithSameOperation.

private void verifyIsColocatedWithSameOperation() {
    colocOut = new TestColocOutInterceptor1();
    // Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    // Local var
    Service ses = control.createMock(Service.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);
    BindingInfo rbi = control.createMock(BindingInfo.class);
    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);
    BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);
    QName op = new QName("E", "F");
    QName intf = new QName("G", "H");
    QName inmi = new QName("M", "in");
    QName outmi = new QName("M", "out");
    ServiceInfo ssi = new ServiceInfo();
    InterfaceInfo sii = new InterfaceInfo(ssi, intf);
    sii.addOperation(op);
    OperationInfo soi = sii.getOperation(op);
    MessageInfo mii = new MessageInfo(soi, MessageInfo.Type.INPUT, inmi);
    MessageInfo mio = new MessageInfo(soi, MessageInfo.Type.OUTPUT, outmi);
    soi.setInput("in", mii);
    soi.setOutput("out", mio);
    ServiceInfo rsi = new ServiceInfo();
    InterfaceInfo rii = new InterfaceInfo(rsi, intf);
    rii.addOperation(op);
    OperationInfo roi = rii.getOperation(op);
    roi.setInput("in", mii);
    roi.setOutput("out", mio);
    EasyMock.expect(sep.getService()).andReturn(ses);
    EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
    EasyMock.expect(s1.getEndpoint()).andReturn(rep);
    EasyMock.expect(rep.getService()).andReturn(res);
    EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
    EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(rei.getBinding()).andReturn(rbi);
    EasyMock.expect(sboi.getName()).andReturn(op);
    EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
    EasyMock.expect(rboi.getName()).andReturn(op);
    EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
    EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);
    control.replay();
    Server val = colocOut.isColocated(list, sep, sboi);
    assertEquals("Expecting a colocated call", s1, val);
    control.reset();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) MessageInfo(org.apache.cxf.service.model.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 25 with ServiceInfo

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

the class ColocOutInterceptorTest method verifyIsColocatedWithCompatibleOperation.

private void verifyIsColocatedWithCompatibleOperation() {
    colocOut = new TestColocOutInterceptor1();
    // Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    // Local var
    Service ses = control.createMock(Service.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);
    BindingInfo rbi = control.createMock(BindingInfo.class);
    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);
    BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);
    QName op = new QName("E", "F");
    QName intf = new QName("G", "H");
    QName inmi = new QName("M", "in");
    QName outmi = new QName("M", "out");
    ServiceInfo ssi = new ServiceInfo();
    InterfaceInfo sii = new InterfaceInfo(ssi, intf);
    sii.addOperation(op);
    OperationInfo soi = sii.getOperation(op);
    MessageInfo mii = new MessageInfo(soi, MessageInfo.Type.INPUT, inmi);
    MessagePartInfo mpi = mii.addMessagePart("parameters");
    mpi.setTypeClass(Source.class);
    MessageInfo mio = new MessageInfo(soi, MessageInfo.Type.OUTPUT, outmi);
    mpi = mio.addMessagePart("parameters");
    mpi.setTypeClass(Source.class);
    soi.setInput("in", mii);
    soi.setOutput("out", mio);
    ServiceInfo rsi = new ServiceInfo();
    InterfaceInfo rii = new InterfaceInfo(rsi, intf);
    rii.addOperation(op);
    OperationInfo roi = rii.getOperation(op);
    mii = new MessageInfo(roi, MessageInfo.Type.INPUT, inmi);
    mpi = mii.addMessagePart("parameters");
    mpi.setTypeClass(Object.class);
    mio = new MessageInfo(roi, MessageInfo.Type.OUTPUT, outmi);
    mpi = mio.addMessagePart("parameters");
    mpi.setTypeClass(Object.class);
    roi.setInput("in", mii);
    roi.setOutput("out", mio);
    EasyMock.expect(sep.getService()).andReturn(ses);
    EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
    EasyMock.expect(s1.getEndpoint()).andReturn(rep);
    EasyMock.expect(rep.getService()).andReturn(res);
    EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
    EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(rei.getBinding()).andReturn(rbi);
    EasyMock.expect(sboi.getName()).andReturn(op);
    EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
    EasyMock.expect(rboi.getName()).andReturn(op);
    EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
    EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);
    control.replay();
    Server val = colocOut.isColocated(list, sep, sboi);
    assertEquals("Expecting a colocated call", s1, val);
    control.reset();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Aggregations

ServiceInfo (org.apache.cxf.service.model.ServiceInfo)195 QName (javax.xml.namespace.QName)89 Test (org.junit.Test)76 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)47 BindingInfo (org.apache.cxf.service.model.BindingInfo)43 OperationInfo (org.apache.cxf.service.model.OperationInfo)37 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)36 Service (org.apache.cxf.service.Service)33 Endpoint (org.apache.cxf.endpoint.Endpoint)31 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)29 File (java.io.File)28 ArrayList (java.util.ArrayList)27 Bus (org.apache.cxf.Bus)26 InputStream (java.io.InputStream)23 Definition (javax.wsdl.Definition)20 Method (java.lang.reflect.Method)16 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)15 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)15 IOException (java.io.IOException)12