Search in sources :

Example 11 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfMixedModeRouterTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            errorHandler(noErrorHandler());
            from(routerEndpointURI).process(new Processor() {

                // convert request message
                public void process(Exchange exchange) throws Exception {
                    CxfPayload<?> message = exchange.getIn().getBody(CxfPayload.class);
                    List<String> params = new ArrayList<String>();
                    if (message != null) {
                        // convert CxfPayload to list of objects any way you like
                        Element element = new XmlConverter().toDOMElement(message.getBody().get(0));
                        params.add(element.getFirstChild().getTextContent());
                    }
                    // replace the body
                    exchange.getIn().setBody(params);
                // if you need to change the operation name
                //exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);      
                }
            }).to(serviceEndpointURI).process(new Processor() {

                // convert response to CxfPayload
                public void process(Exchange exchange) throws Exception {
                    List<?> list = exchange.getIn().getBody(List.class);
                    CxfPayload<SoapHeader> message = null;
                    if (list != null) {
                        // convert the list of objects to CxfPayload any way you like
                        String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">" + "<return xmlns=\"http://cxf.component.camel.apache.org/\">" + list.get(0) + "</return></ns1:echoResponse>";
                        List<Element> body = new ArrayList<Element>();
                        body.add(StaxUtils.read(new StringReader(s)).getDocumentElement());
                        message = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), body);
                    }
                    exchange.getIn().setBody(message);
                    // we probably should be smarter in detecting data format based on message body
                    // but for now we need to explicitly reset the mode (see CAMEL-3420)
                    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
                }
            });
        }
    };
}
Also used : Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(org.w3c.dom.Element) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter) Exchange(org.apache.camel.Exchange) StringReader(java.io.StringReader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class LoadDistributorFeatureTest method startRoute.

private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
    ctx.addRoutes(new RouteBuilder() {

        public void configure() {
            List<String> serviceList = new ArrayList<String>();
            serviceList.add(SERVICE_ADDRESS_1);
            serviceList.add(SERVICE_ADDRESS_2);
            SequentialStrategy strategy = new SequentialStrategy();
            strategy.setAlternateAddresses(serviceList);
            LoadDistributorFeature ldf = new LoadDistributorFeature();
            ldf.setStrategy(strategy);
            CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
            endpoint.getFeatures().add(ldf);
            from(proxy).to(endpoint);
        }
    });
    ctx.start();
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RouteBuilder(org.apache.camel.builder.RouteBuilder) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfMessageHeadersRelayTest method testInoutHeaderCXFClientNoServiceClassNoRelay.

@Test
public void testInoutHeaderCXFClientNoServiceClassNoRelay() throws Exception {
    // TODO: Fix this test later
    QName qname = QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SOAPHeaderInfo");
    String uri = "cxf:bean:routerNoRelayNoServiceClassEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy";
    String requestHeader = "<ns2:SOAPHeaderInfo xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><originator>CxfSoapHeaderRoutePropagationTest.testInOutHeader Requestor" + "</originator><message>Invoking CxfSoapHeaderRoutePropagationTest.testInOutHeader() Request" + "</message></ns2:SOAPHeaderInfo>";
    String requestBody = "<ns2:inoutHeader xmlns:ns2=\"http://apache.org/camel/component/cxf/soap/headers\">" + "<requestType>CXF user</requestType></ns2:inoutHeader>";
    List<Source> elements = new ArrayList<Source>();
    elements.add(new DOMSource(StaxUtils.read(new StringReader(requestBody)).getDocumentElement()));
    final List<SoapHeader> headers = new ArrayList<SoapHeader>();
    headers.add(new SoapHeader(qname, StaxUtils.read(new StringReader(requestHeader)).getDocumentElement()));
    final CxfPayload<SoapHeader> cxfPayload = new CxfPayload<SoapHeader>(headers, elements, null);
    Exchange exchange = template.request(uri, new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(cxfPayload);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inoutHeader");
            exchange.getIn().setHeader(Header.HEADER_LIST, headers);
        }
    });
    CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
    assertEquals(1, out.getBodySources().size());
    assertTrue(out.getBodySources().get(0) instanceof DOMSource);
    assertEquals(0, out.getHeaders().size());
    String responseExp = "<ns2:inoutHeaderResponse xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><responseType>pass</responseType>" + "</ns2:inoutHeaderResponse>";
    String response = StaxUtils.toString(out.getBody().get(0));
    //REVISIT use a more reliable comparison to tolerate some namespaces being added to the root element
    assertTrue(response, response.startsWith(responseExp.substring(0, 87)) && response.endsWith(responseExp.substring(88, responseExp.length())));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Processor(org.apache.camel.Processor) CxfPayload(org.apache.camel.component.cxf.CxfPayload) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) JAXBException(javax.xml.bind.JAXBException) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) StringReader(java.io.StringReader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Test(org.junit.Test)

Example 14 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.

protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
    List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
    List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }
    assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
                hdrToTest.add((OutofBandHeader) job.getValue());
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }
    assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
    assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
    assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
    assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 15 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DefaultCxfRsBindingTest method testCopyProtocolHeader.

@Test
public void testCopyProtocolHeader() {
    DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
    cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    Message camelMessage = new DefaultMessage();
    org.apache.cxf.message.Message cxfMessage = new MessageImpl();
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("emptyList", Collections.EMPTY_LIST);
    headers.put("zeroSizeList", new ArrayList<String>(0));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange);
    assertNull("We should get nothing here", camelMessage.getHeader("emptyList"));
    assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) ArrayList(java.util.ArrayList) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611