Search in sources :

Example 61 with BindingOperationInfo

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

the class JaxWsServiceFactoryBean method initializeWSDLOperationsForProvider.

protected void initializeWSDLOperationsForProvider() {
    Class<?> c = getProviderParameterType(getServiceClass());
    if (c == null) {
        throw new ServiceConstructionException(new Message("INVALID_PROVIDER_EXC", LOG));
    }
    if (getEndpointInfo() == null && isFromWsdl()) {
        // most likely, they specified a WSDL, but for some reason
        // did not give a valid ServiceName/PortName.  For provider,
        // we'll allow this since everything is bound directly to
        // the invoke method, however, this CAN cause other problems
        // such as addresses in the wsdl not getting updated and such
        // so we'll WARN about it.....
        List<QName> enames = new ArrayList<>();
        for (ServiceInfo si : getService().getServiceInfos()) {
            for (EndpointInfo ep : si.getEndpoints()) {
                enames.add(ep.getName());
            }
        }
        LOG.log(Level.WARNING, "COULD_NOT_FIND_ENDPOINT", new Object[] { getEndpointName(), enames });
    }
    try {
        Method invoke = getServiceClass().getMethod("invoke", c);
        QName catchAll = new QName("http://cxf.apache.org/jaxws/provider", "invoke");
        // Bind every operation to the invoke method.
        for (ServiceInfo si : getService().getServiceInfos()) {
            si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
            if (!isFromWsdl()) {
                for (EndpointInfo ei : si.getEndpoints()) {
                    ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
                }
            }
            for (BindingInfo bind : si.getBindings()) {
                for (BindingOperationInfo bop : bind.getOperations()) {
                    OperationInfo o = bop.getOperationInfo();
                    if (bop.isUnwrappedCapable()) {
                        // force to bare, no unwrapping
                        bop.getOperationInfo().setUnwrappedOperation(null);
                        bop.setUnwrappedOperation(null);
                    }
                    if (o.getInput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getInput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getInput().addMessagePart(o.getName());
                            inf.setConcreteName(o.getName());
                            messageParts = o.getInput().getMessageParts();
                            bop.getInput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getInput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    if (o.getOutput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getOutput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getOutput().addMessagePart(o.getName());
                            inf.setConcreteName(new QName(o.getName().getNamespaceURI(), o.getName().getLocalPart() + "Response"));
                            messageParts = o.getOutput().getMessageParts();
                            bop.getOutput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getOutput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    getMethodDispatcher().bind(o, invoke);
                }
                BindingOperationInfo bop = bind.getOperation(catchAll);
                if (bop == null) {
                    OperationInfo op = bind.getInterface().getOperation(catchAll);
                    if (op == null) {
                        op = bind.getInterface().addOperation(catchAll);
                        String name = catchAll.getLocalPart();
                        MessageInfo mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Request"), MessageInfo.Type.INPUT);
                        op.setInput(catchAll.getLocalPart() + "Request", mInfo);
                        MessagePartInfo mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Response"), MessageInfo.Type.OUTPUT);
                        op.setOutput(name + "Response", mInfo);
                        mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        BindingOperationInfo bo = new BindingOperationInfo(bind, op);
                        op.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bo.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bind.addOperation(bo);
                    }
                }
            }
        }
    } catch (SecurityException e) {
        throw new ServiceConstructionException(e);
    } catch (NoSuchMethodException e) {
        throw new ServiceConstructionException(e);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) 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) BindingInfo(org.apache.cxf.service.model.BindingInfo)

Example 62 with BindingOperationInfo

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

the class JAXWSMethodInvokerTest method prepareJAXWSMethodInvoker.

private JAXWSMethodInvoker prepareJAXWSMethodInvoker(Exchange ex, Object serviceObject, Method serviceMethod) throws Throwable {
    EasyMock.reset(factory);
    factory.create(ex);
    EasyMock.expectLastCall().andReturn(serviceObject).anyTimes();
    factory.release(ex, serviceObject);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(factory);
    BindingOperationInfo boi = new BindingOperationInfo();
    ex.put(BindingOperationInfo.class, boi);
    Service serviceClass = EasyMock.createMock(Service.class);
    serviceClass.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    serviceClass.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    ex.put(Service.class, serviceClass);
    MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
    serviceClass.get(MethodDispatcher.class.getName());
    EasyMock.expectLastCall().andReturn(md).anyTimes();
    md.getMethod(boi);
    EasyMock.expectLastCall().andReturn(serviceMethod).anyTimes();
    EasyMock.replay(md);
    EasyMock.replay(serviceClass);
    // initialize the contextCache
    ex.getInMessage().getContextualProperty("dummy");
    return new JAXWSMethodInvoker(factory);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher)

Example 63 with BindingOperationInfo

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

the class ServiceModelUtilsTest method testGetOperationInputPartNamesRpc.

@Test
public void testGetOperationInputPartNamesRpc() throws Exception {
    getService(getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl"), RPCLitGreeterImpl.class, new QName("http://apache.org/hello_world_rpclit", "SoapPortRPCLit"));
    BindingOperationInfo operation = ServiceModelUtil.getOperation(message.getExchange(), "greetMe");
    assertNotNull(operation);
    List<String> names = ServiceModelUtil.getOperationInputPartNames(operation.getOperationInfo());
    assertNotNull(names);
    assertEquals(1, names.size());
    assertEquals("in", names.get(0));
    operation = ServiceModelUtil.getOperation(message.getExchange(), "sayHi");
    assertNotNull(operation);
    names = ServiceModelUtil.getOperationInputPartNames(operation.getOperationInfo());
    assertNotNull(names);
    assertEquals(0, names.size());
    operation = ServiceModelUtil.getOperation(message.getExchange(), "greetUs");
    assertNotNull(operation);
    names = ServiceModelUtil.getOperationInputPartNames(operation.getOperationInfo());
    assertNotNull(names);
    assertEquals(2, names.size());
// System.err.println(names);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 64 with BindingOperationInfo

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

the class DispatchTest method testFindOperationWithSource.

@Test
public void testFindOperationWithSource() throws Exception {
    ServiceImpl service = new ServiceImpl(getBus(), getClass().getResource("/wsdl/hello_world.wsdl"), serviceName, null);
    Dispatch<Source> disp = service.createDispatch(portName, Source.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    disp.getRequestContext().put("find.dispatch.operation", Boolean.TRUE);
    d.setMessageObserver(new MessageReplayObserver("/org/apache/cxf/jaxws/sayHiResponse.xml"));
    BindingOperationVerifier bov = new BindingOperationVerifier();
    ((DispatchImpl<?>) disp).getClient().getOutInterceptors().add(bov);
    Document doc = StaxUtils.read(getResourceAsStream("/org/apache/cxf/jaxws/sayHi2.xml"));
    DOMSource source = new DOMSource(doc);
    Source res = disp.invoke(source);
    assertNotNull(res);
    BindingOperationInfo boi = bov.getBindingOperationInfo();
    assertNotNull(boi);
    assertEquals(new QName("http://apache.org/hello_world_soap_http", "sayHi"), boi.getName());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) ServiceImpl(org.apache.cxf.jaxws.ServiceImpl) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) MessageReplayObserver(org.apache.cxf.jaxws.MessageReplayObserver) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 65 with BindingOperationInfo

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

the class SOAPLoggingTest method testSoap.

@Test
public void testSoap() {
    DefaultLogEventMapper mapper = new DefaultLogEventMapper();
    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    ServiceInfo service = new ServiceInfo();
    BindingInfo info = new BindingInfo(service, "bindingId");
    SoapBinding value = new SoapBinding(info);
    exchange.put(Binding.class, value);
    OperationInfo opInfo = new OperationInfo();
    opInfo.setName(new QName("http://my", "Operation"));
    BindingOperationInfo boi = new BindingOperationInfo(info, opInfo);
    exchange.put(BindingOperationInfo.class, boi);
    message.setExchange(exchange);
    LogEvent event = mapper.map(message);
    Assert.assertEquals("{http://my}Operation", event.getOperationName());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) DefaultLogEventMapper(org.apache.cxf.ext.logging.event.DefaultLogEventMapper) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16