Java 类org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy 实例源码

项目:Camel    文件:SoapJaxbDataFormat.java   
/**
 * Unmarshal a given SOAP xml stream and return the content of the SOAP body
 * @throws IOException,SAXException
 */
public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, SAXException {
    checkElementNameStrategy(exchange);

    String soapAction = getSoapActionFromExchange(exchange);

    // Determine the method name for an eventual BeanProcessor in the route
    if (soapAction != null && elementNameStrategy instanceof ServiceInterfaceStrategy) {
        ServiceInterfaceStrategy strategy = (ServiceInterfaceStrategy) elementNameStrategy;
        String methodName = strategy.getMethodForSoapAction(soapAction);
        exchange.getOut().setHeader(Exchange.BEAN_METHOD_NAME, methodName);
    }

    // Store soap action for an eventual later marshal step.
    // This is necessary as the soap action in the message may get lost on the way
    if (soapAction != null) {
        exchange.setProperty(Exchange.SOAP_ACTION, soapAction);
    }

    Object unmarshalledObject = super.unmarshal(exchange, stream);
    Object rootObject = JAXBIntrospector.getValue(unmarshalledObject);

    return adapter.doUnmarshal(exchange, stream, rootObject);
}
项目:Camel    文件:ServiceInterfaceStrategyTest.java   
@Test
public void testServiceInterfaceStrategyWithServer() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, false);

    // Tests the case where the action is not found but the type is
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByNameResponse.class);
    assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByNameResponse", elName.getLocalPart());

    // Tests the case where the soap action is found
    QName elName2 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getCustomersByName",
            GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    assertEquals("getCustomersByNameResponse", elName2.getLocalPart());

    // this tests the case that the soap action as well as the type are not
    // found
    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
项目:Camel    文件:MultiPartClientMarshalTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {

            ServiceInterfaceStrategy strat =  
                   new ServiceInterfaceStrategy(com.example.customerservice.multipart.MultiPartCustomerService.class, true);
            SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat("com.example.customerservice.multipart", strat);

            from("direct:start")
                    .marshal(soapDataFormat)
                    .log("marshal to: ${body}")
                    .end();
        }
    };
}
项目:Camel    文件:ServiceInterfaceStrategyTest.java   
@Test
public void testServiceInterfaceStrategyWithClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByName", elName.getLocalPart());

    QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    assertEquals("getCustomersByName", elName2.getLocalPart());

    // Tests the case where the soap action is found but the in type is null
    QName elName3 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getAllCustomers",
            null);
    assertNull(elName3);

    QName elName4 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getAllAmericanCustomers",
            null);
    assertNull(elName4);

    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
项目:Camel    文件:ServiceInterfaceStrategyTest.java   
@Test
public void testServiceInterfaceStrategyWithRequestWrapperAndClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(
            com.example.customerservice2.CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("", com.example.customerservice2.GetCustomersByName.class);
    assertEquals("http://customerservice2.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByName", elName.getLocalPart());

    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
项目:Camel    文件:ServiceInterfaceStrategyTest.java   
@Test
public void testWithNonWebservice() {
    try {
        new ServiceInterfaceStrategy(Object.class, true);
        fail("Should throw an exception for a class that is no webservice");
    } catch (IllegalArgumentException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
项目:Camel    文件:ServiceInterfaceStrategyTest.java   
@Test
public void testMultiPart() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(MultiPartCustomerService.class, true);
    QName custNameQName = strategy.findQNameForSoapActionOrType("http://multipart.customerservice.example.com/getCustomersByName",
                                                                com.example.customerservice.multipart.GetCustomersByName.class);
    QName custTypeQName = strategy.findQNameForSoapActionOrType("http://multipart.customerservice.example.com/getCustomersByName",
                                                                com.example.customerservice.multipart.Product.class);

    assertEquals("http://multipart.customerservice.example.com/", custNameQName.getNamespaceURI());
    assertEquals("getCustomersByName", custNameQName.getLocalPart());

    assertEquals("http://multipart.customerservice.example.com/", custTypeQName.getNamespaceURI());
    assertEquals("product", custTypeQName.getLocalPart());
}
项目:Camel    文件:SoapCxfClientTest.java   
public void configure() throws Exception {
    String jaxbPackage = GetCustomersByName.class.getPackage().getName();
    ElementNameStrategy elNameStrat = new ServiceInterfaceStrategy(CustomerService.class, false);
    SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(jaxbPackage, elNameStrat);
    getContext().setTracing(true);
    from("direct:cxfclient") //
            .onException(Exception.class).handled(true).marshal(soapDataFormat).end() //
            .unmarshal(soapDataFormat) //
            .bean(serverBean) //
            .marshal(soapDataFormat);
}
项目:Camel    文件:SoapCxfServerTest.java   
public void configure() throws Exception {
    String jaxbPackage = GetCustomersByName.class.getPackage().getName();
    ElementNameStrategy elNameStrat = new ServiceInterfaceStrategy(CustomerService.class, true);
    SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(jaxbPackage, elNameStrat);
    from("direct:camelClient") //
        .marshal(soapDataFormat) //
        .to("direct:cxfEndpoint") //
        .unmarshal(soapDataFormat);
}
项目:Camel    文件:MultiPartCxfServerTest.java   
@Override
public void configure() throws Exception {
    ServiceInterfaceStrategy strat =  
        new ServiceInterfaceStrategy(com.example.customerservice.multipart.MultiPartCustomerService.class, true);
    SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat("com.example.customerservice.multipart", strat);

    from("direct:start")
         .marshal(soapDataFormat)
         .log("marshal to: ${body}")
         .to("direct:cxfEndpoint")
         .unmarshal(soapDataFormat)
         .end();
}
项目:Camel    文件:SoapClientTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        String jaxbPackage = GetCustomersByName.class.getPackage().getName();

        @Override
        public void configure() throws Exception {
            ElementNameStrategy elNameStrat = new ServiceInterfaceStrategy(CustomerService.class, true);
            SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(jaxbPackage, elNameStrat);
            final InputStream in = this.getClass().getResourceAsStream("response.xml");
            from("direct:start").marshal(soapDataFormat).process(new FileReplyProcessor(in))
                    .unmarshal(soapDataFormat);
        }
    };
}
项目:t5-doc    文件:ApplicationConfiguration.java   
@Bean(name = "rivtaObservationsDataFormat")
public SoapJaxbDataFormat soapJaxbDataFormat() {
    return new SoapJaxbDataFormat("se.riv.clinicalprocess.healthcond.basic.getobservationsresponder.v1",
            new ServiceInterfaceStrategy(
                    se.riv.clinicalprocess.healthcond.basic.getobservations.v1.rivtabp21.GetObservationsResponderInterface.class,
                    false));
}
项目:wildfly-camel    文件:SOAPServiceInterfaceStrategyIntegrationTest.java   
@Test
public void testSOAPServiceInterfaceStrategyMarshal() throws Exception {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat("org.wildfly.camel.test.common.types", strategy);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(format);
        }
    });

    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope.xml")) {
        Customer customer = new Customer();
        customer.setFirstName("Kermit");
        customer.setLastName("The Frog");

        ProducerTemplate template = camelctx.createProducerTemplate();
        String result = template.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(XMLUtils.compactXML(input), XMLUtils.compactXML(result));
    } finally {
        camelctx.stop();
    }
}