Java 类org.apache.camel.component.cxf.common.message.CxfConstants 实例源码

项目:camel-springboot    文件:SoapCallWithObjectTest.java   
@Bean
public RouteBuilder createSoapService() {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("cxf:/GlobalWeather?serviceClass=" + GlobalWeatherSoap.class.getName())
                    .routeId("test-GlobalWeatherSoap")
                    .toD("direct:${header." + CxfConstants.OPERATION_NAME + "}");

            from("direct:GetCitiesByCountry")
                .setProperty("country",simple("${body[0]}",String.class)) //The method arguments are in a org.apache.cxf.message.MessageContentsList
                .process((e) -> {
                    switch(e.getProperty("country",String.class)) {
                    case "TEST":
                        e.getIn().setBody("<NewDataSet><Table><Country>TEST</Country><City>AA</City></Table><Table><Country>TEST</Country><City>BB</City></Table></NewDataSet>");
                        break;
                    default:
                        e.getIn().setBody("<NewDataSet/>");
                    }
                });

        }

    };
}
项目:Camel    文件:CxfEndpointBeansTest.java   
@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    ProducerTemplate template = context.createProducerTemplate();

    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {
        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });

    Exception ex = reply.getException();
    assertTrue("Should get the fault here", 
               ex instanceof org.apache.cxf.interceptor.Fault
               || ex instanceof HTTPException);
}
项目:Camel    文件:MyProcessor.java   
public void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    // Get the parameter list
    List<?> parameter = in.getBody(List.class);
    // Get the operation name
    String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
    Object result = null;
    if ("sayHi".equals(operation)) {
        result = " Hello buddy!";
    } 
    if ("greetMe".equals(operation)) {
        result = " Hello " +  (String)parameter.get(0);            
    }
    // Put the result back
    exchange.getOut().setBody(result);        
}
项目:Camel    文件:CamelGreeterTest.java   
@Test
public void testMocksAreValid() throws Exception {
    assertNotNull(camelContext);
    assertNotNull(resultEndpoint);

    ProducerTemplate template = camelContext.createProducerTemplate();
    template.sendBodyAndHeader("jms:requestQueue", "Willem", CxfConstants.OPERATION_NAME, "greetMe");

    // Sleep a while and wait for the message whole processing
    Thread.sleep(4000);
    template.stop();

    MockEndpoint.assertIsSatisfied(camelContext);
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    assertEquals("Should get one message", list.size(), 1);
    for (Exchange exchange : list) {
        String result = (String) exchange.getIn().getBody();
        assertEquals("Get the wrong result ", result, "Hello Willem");
    }
}
项目:Camel    文件:CamelGreeterConsumerTest.java   
@Test
public void testInvokeServers() throws Exception {
    assertNotNull(camelContext);

    ProducerTemplate template = camelContext.createProducerTemplate();
    List<String> params = new ArrayList<String>();
    params.add("Willem");
    Object result = template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut,
                                               params, CxfConstants.OPERATION_NAME, "greetMe");
    assertTrue("Result is a list instance ", result instanceof List);
    assertEquals("Get the wrong response", ((List<?>)result).get(0), "HelloWillem");
    try {
        template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut,
                                        params, CxfConstants.OPERATION_NAME, "pingMe");
        fail("Expect exception here.");
    } catch (Exception ex) {
        assertTrue("Get a wrong exception.", ex instanceof CamelExecutionException);
        assertTrue("Get a wrong exception cause. ", ex.getCause() instanceof PingMeFault);
    }
    template.stop();
}
项目:Camel    文件:MulticastCxfTest.java   
@Test
public void testMulticastCXF() throws Exception {
    replyEndpoint.expectedBodiesReceived("Hello Willem", "Hello Claus", "Hello Jonathan");
    reply2Endpoint.expectedBodiesReceived("Bye Willem", "Bye Claus", "Bye Jonathan");
    outputEndpoint.expectedBodiesReceived("Bye Willem", "Bye Claus", "Bye Jonathan");

    // returns the last message from the recipient list
    String out = template.requestBodyAndHeader("direct:start", "Willem", CxfConstants.OPERATION_NAME, "greetMe", String.class);
    assertEquals("Bye Willem", out);

    // call again to ensure that works also
    // returns the last message from the recipient list
    String out2 = template.requestBodyAndHeader("direct:start", "Claus", CxfConstants.OPERATION_NAME, "greetMe", String.class);
    assertEquals("Bye Claus", out2);

    // and call again to ensure that it really works also
    // returns the last message from the recipient list
    String out3 = template.requestBodyAndHeader("direct:start", "Jonathan", CxfConstants.OPERATION_NAME, "greetMe", String.class);
    assertEquals("Bye Jonathan", out3);

    replyEndpoint.assertIsSatisfied();
    reply2Endpoint.assertIsSatisfied();
    outputEndpoint.assertIsSatisfied();
}
项目:Camel    文件:CxfRsProducer.java   
@SuppressWarnings("unchecked")
protected void setupClientQueryAndHeaders(WebClient client, Exchange exchange) throws Exception {
    Message inMessage = exchange.getIn();
    CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
    // check if there is a query map in the message header
    Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, Map.class);
    if (maps == null) {
        // Get the map from HTTP_QUERY header
        String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
        if (queryString != null) {
            maps = getQueryParametersFromQueryString(queryString,
                                                     IOHelper.getCharsetName(exchange));
        }
    }
    if (maps == null) {
        maps = cxfRsEndpoint.getParameters();
    }
    if (maps != null) {
        for (Map.Entry<String, String> entry : maps.entrySet()) {
            client.query(entry.getKey(), entry.getValue());
        }
    }

    setupClientHeaders(client, exchange);

}
项目:Camel    文件:CxfEndpointBeansRouterTest.java   
@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
    ProducerTemplate template = camelContext.createProducerTemplate();

    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {
        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });

    Exception ex = reply.getException();
    assertTrue("Should get the fault here", 
               ex instanceof org.apache.cxf.interceptor.Fault
               || ex instanceof HTTPException);
}
项目:Camel    文件:DefaultCxfBindingTest.java   
@Test
public void testPopupalteExchangeFromCxfResponseOfNullBody() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> responseContext = new HashMap<String, Object>();
    responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    cxfExchange.setInMessage(cxfMessage);

    cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);

    CxfPayload<?> cxfPayload = exchange.getOut().getBody(CxfPayload.class);

    assertNotNull(cxfPayload);
    List<?> body = cxfPayload.getBody(); 
    assertNotNull(body);
    assertEquals(0, body.size());
}
项目:Camel    文件:DefaultCxfBindingTest.java   
@Test
public void testPopupalteExchangeFromCxfRequestWithHeaderMerged() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("myfruitheader", Arrays.asList("peach"));
    headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);

    cxfExchange.setInMessage(cxfMessage);

    cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange);

    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
}
项目:Camel    文件:CxfMessageHeadersRelayTest.java   
protected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
    // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<Object> params = new ArrayList<Object>();
    Me me = new Me();
    me.setFirstName("john");
    me.setLastName("Doh");

    params.add(me);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader");

    Exchange exchange = template.send(producerUri, senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    MessageContentsList result = (MessageContentsList)out.getBody();
    assertTrue("Expected the out of band header to propagate but it didn't", 
               result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass"));
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    validateReturnedOutOfBandHeader(responseContext);
}
项目:Camel    文件:CxfRsConsumerTest.java   
public void process(Exchange exchange) throws Exception {
    Message inMessage = exchange.getIn();                        
    // Get the operation name from in message
    String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
    if ("getCustomer".equals(operationName)) {
        processGetCustomer(exchange);
    } else if ("updateCustomer".equals(operationName)) {
        assertEquals("Get a wrong customer message header", "header1;header2", inMessage.getHeader("test"));
        String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
        assertEquals("Get a wrong http method", "PUT", httpMethod);
        Customer customer = inMessage.getBody(Customer.class);
        assertNotNull("The customer should not be null.", customer);
        // Now you can do what you want on the customer object
        assertEquals("Get a wrong customer name.", "Mary", customer.getName());
        // set the response back
        exchange.getOut().setBody(Response.ok().build());
    }

}
项目:Camel    文件:CxfRsSslProducerTest.java   
@Override
public void process(Exchange exchange) throws Exception {
    exchange.setPattern(ExchangePattern.InOut);
    Message inMessage = exchange.getIn();
    setupDestinationURL(inMessage);
    // using the http central client API
    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
    // set the Http method
    inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
    // set the relative path
    inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
    // Specify the response class , cxfrs will use InputStream as the response object type
    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
    // set a customer header
    inMessage.setHeader("key", "value");
    // since we use the Get method, so we don't need to set the message body
    inMessage.setBody(null);
}
项目:Camel    文件:CxfRsProducerHeaderTest.java   
public void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    Message out = exchange.getOut();

    if (in.getHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API) != null) {
        // this should have been filtered
        out.setHeader("failed-header-using-http-api", CxfConstants.CAMEL_CXF_RS_USING_HTTP_API);
    }

    out.setHeader("echo-accept", in.getHeader("Accept"));
    out.setHeader("echo-my-user-defined-header", in.getHeader("my-user-defined-header"));

    exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
    exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/xml");


}
项目:Camel    文件:CxfProducerRouterTest.java   
@Test
public void testInvokingSimpleServerWithParams() throws Exception {
 // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<String> params = new ArrayList<String>();
    // Prepare the request message for the camel-cxf procedure
    params.add(TEST_MESSAGE);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);

    Exchange exchange = template.send("direct:EndpointA", senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    // The response message's body is an MessageContentsList which first element is the return value of the operation,
    // If there are some holder parameters, the holder parameter will be filled in the reset of List.
    // The result will be extract from the MessageContentsList with the String class type
    MessageContentsList result = (MessageContentsList)out.getBody();
    LOG.info("Received output text: " + result.get(0));
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
    assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));
 // END SNIPPET: sending
}
项目:Camel    文件:CxfHeaderHelperTest.java   
@Test
public void testPropagateCxfToCamelWithMerged() {
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE);

    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> cxfHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    cxfHeaders.put("myfruitheader", Arrays.asList("peach"));
    cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders);

    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), 
                                        cxfMessage, camelHeaders, exchange);

    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
}
项目:Camel    文件:CamelRouterBuilder.java   
public void process(Exchange exchange) throws Exception {
    String operationName = exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
    Method method = findMethod(operationName, exchange.getIn().getBody(Object[].class));
    try {
        Object response = method.invoke(instance, exchange.getIn().getBody(Object[].class));
        exchange.getOut().setBody(response);
    }  catch (InvocationTargetException e) {
        throw (Exception)e.getCause();
    }
}
项目:Camel    文件:MyProcessor.java   
public void process(Exchange exchange) throws Exception {
    Thread.sleep(1000);
    Message in = exchange.getIn();
    // Get the parameter list
    List<?> parameter = in.getBody(List.class);
    // Get the operation name
    String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
    Object result = operation + " " + (String)parameter.get(0);
    exchange.getOut().setBody(result);
}
项目:Camel    文件:JmsToCxfInOutTest.java   
@Test
public void testJmsToCxfInOut() throws Exception {
    assertNotNull(template);

    String out = template.requestBodyAndHeader("jms:queue:bridge.cxf", "Willem", CxfConstants.OPERATION_NAME, "greetMe", String.class);
    assertEquals("Hello Willem", out);

    // call for the other opertion
    out = template.requestBodyAndHeader("jms:queue:bridge.cxf", new Object[0], CxfConstants.OPERATION_NAME, "sayHi", String.class);
    assertEquals("Bonjour", out);
}
项目:Camel    文件:CxfToJmsInOutTest.java   
@Test
public void testCxfToJmsInOut() throws Exception {
    assertNotNull(template);
    assertNotNull(inputEndpoint);
    assertNotNull(outputEndpoint);

    inputEndpoint.expectedBodiesReceived("Willem");
    outputEndpoint.expectedBodiesReceived("Hello Willem");

    String out = template.requestBodyAndHeader("cxf://bean:serviceEndpoint", "Willem", CxfConstants.OPERATION_NAME, "greetMe", String.class);
    assertEquals("Hello Willem", out);

    inputEndpoint.assertIsSatisfied();
    outputEndpoint.assertIsSatisfied();
}
项目:Camel    文件:JmsPrepareResponse.java   
public void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    if ("greetMe".equals(in.getHeader(CxfConstants.OPERATION_NAME))) {
        String request = in.getBody(String.class);               
        exchange.getOut().setBody("Hello" + request);
    } else {
        // throw the Exception
        FaultDetail faultDetail = new FaultDetail();
        faultDetail.setMajor((short)2);
        faultDetail.setMinor((short)1);
        exchange.getOut().setBody(new PingMeFault("PingMeFault raised by server", faultDetail));
        exchange.getOut().setFault(true);

    }
}
项目:Camel    文件:PrepareRequest.java   
public void process(Exchange exchange) throws Exception {
    List<String> params = new ArrayList<String>();
    params.add(exchange.getIn().getBody(String.class));
    exchange.getOut().setBody(params);
    String operation = (String)exchange.getIn().getHeader(CxfConstants.OPERATION_NAME);
    LOG.info("The operation name is " + operation);
    exchange.getOut().setHeader(CxfConstants.OPERATION_NAME, operation);
}
项目:Camel    文件:CxfEndpointUtils.java   
public static QName getPortName(final CxfEndpoint endpoint) {
    if (endpoint.getPortName() != null) {
        return endpoint.getPortName();
    } else {
        String portLocalName = getCxfEndpointPropertyValue((CxfSpringEndpoint)endpoint, CxfConstants.PORT_LOCALNAME);
        String portNamespace = getCxfEndpointPropertyValue((CxfSpringEndpoint)endpoint, CxfConstants.PORT_NAMESPACE);
        if (portLocalName != null) {
            return new QName(portNamespace, portLocalName);
        } else {
            return null;
        }           
    }
}
项目:Camel    文件:CxfEndpointUtils.java   
public static QName getServiceName(final CxfEndpoint endpoint) {
    if (endpoint.getServiceName() != null) {
        return endpoint.getServiceName();
    } else {
        String serviceLocalName = getCxfEndpointPropertyValue((CxfSpringEndpoint)endpoint, CxfConstants.SERVICE_LOCALNAME);
        String serviceNamespace = getCxfEndpointPropertyValue((CxfSpringEndpoint)endpoint, CxfConstants.SERVICE_NAMESPACE);
        if (serviceLocalName != null) {
            return new QName(serviceNamespace, serviceLocalName);
        } else {
            return null;
        }
    }
}
项目:Camel    文件:CxfConsumer.java   
protected boolean isAsyncInvocationSupported(Exchange cxfExchange) {
    Message cxfMessage = cxfExchange.getInMessage();
    Object addressingProperties = cxfMessage.get(CxfConstants.WSA_HEADERS_INBOUND);
    if (addressingProperties != null 
           && !ContextUtils.isGenericAddress(getReplyTo(addressingProperties))) {
        //it's decoupled endpoint, so already switch thread and
        //use executors, which means underlying transport won't 
        //be block, so we shouldn't rely on continuation in 
        //this case, as the SuspendedInvocationException can't be 
        //caught by underlying transport. So we should use the SyncInvocation this time
        return false;
    }
    // we assume it should support AsyncInvocation out of box
    return true;
}
项目:Camel    文件:CxfConsumer.java   
@SuppressWarnings("unchecked")
private void setResponseBack(Exchange cxfExchange, org.apache.camel.Exchange camelExchange) {
    CxfEndpoint endpoint = (CxfEndpoint)getEndpoint();
    CxfBinding binding = endpoint.getCxfBinding();

    checkFailure(camelExchange, cxfExchange);

    binding.populateCxfResponseFromExchange(camelExchange, cxfExchange);

    // check failure again as fault could be discovered by converter
    checkFailure(camelExchange, cxfExchange);

    // copy the headers javax.xml.ws header back
    binding.copyJaxWsContext(cxfExchange, (Map<String, Object>)camelExchange.getProperty(CxfConstants.JAXWS_CONTEXT));
}
项目:Camel    文件:CxfProducer.java   
protected Map<String, Object> prepareRequest(Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) throws Exception {

    // create invocation context
    WrappedMessageContext requestContext = new WrappedMessageContext(
            new HashMap<String, Object>(), null, Scope.APPLICATION);

    camelExchange.setProperty(Message.MTOM_ENABLED, String.valueOf(endpoint.isMtomEnabled()));

    // set data format mode in exchange
    DataFormat dataFormat = endpoint.getDataFormat();
    camelExchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, dataFormat);   
    LOG.trace("Set Camel Exchange property: {}={}", DataFormat.class.getName(), dataFormat);

    if (endpoint.getMergeProtocolHeaders()) {
        camelExchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE);
    }

    // set data format mode in the request context
    requestContext.put(DataFormat.class.getName(), dataFormat);

    // don't let CXF ClientImpl close the input stream 
    if (dataFormat.dealias() == DataFormat.RAW) {
        cxfExchange.put(Client.KEEP_CONDUIT_ALIVE, true);
        LOG.trace("Set CXF Exchange property: {}={}", Client.KEEP_CONDUIT_ALIVE, true);
    }

    // bind the request CXF exchange
    endpoint.getCxfBinding().populateCxfRequestFromExchange(cxfExchange, camelExchange, 
            requestContext);

    // Remove protocol headers from scopes.  Otherwise, response headers can be
    // overwritten by request headers when SOAPHandlerInterceptor tries to create
    // a wrapped message context by the copyScoped() method.
    requestContext.getScopes().remove(Message.PROTOCOL_HEADERS);

    return requestContext.getWrappedMap();
}
项目:Camel    文件:CxfRsProducer.java   
public void process(Exchange exchange) throws Exception {
    Message inMessage = exchange.getIn();
    Boolean httpClientAPI = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.class);
    // set the value with endpoint's option
    if (httpClientAPI == null) {
        httpClientAPI = ((CxfRsEndpoint) getEndpoint()).isHttpClientAPI();
    }
    if (httpClientAPI.booleanValue()) {
        invokeHttpClient(exchange);
    } else {
        invokeProxyClient(exchange);
    }
}
项目:Camel    文件:DefaultCxfRsBinding.java   
public void populateExchangeFromCxfRsRequest(org.apache.cxf.message.Exchange cxfExchange,
                                             Exchange camelExchange, Method method, Object[] paramArray) {
    Message camelMessage = camelExchange.getIn();        
    //Copy the CXF message header into the Camel inMessage
    org.apache.cxf.message.Message cxfMessage = cxfExchange.getInMessage();

    // TODO use header filter strategy and cxfToCamelHeaderMap
    CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage);

    // setup the charset from content-type header
    setCharsetWithContentType(camelExchange);

    //copy the protocol header
    copyProtocolHeader(cxfMessage, camelMessage, camelMessage.getExchange());

    camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, method.getReturnType());

    camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, method.getGenericReturnType());

    copyOperationResourceInfoStack(cxfMessage, camelMessage);

    camelMessage.setHeader(CxfConstants.OPERATION_NAME, method.getName());

    camelMessage.setHeader(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage);

    camelMessage.setBody(new MessageContentsList(paramArray));

    // propagate the security subject from CXF security context
    SecurityContext securityContext = cxfMessage.get(SecurityContext.class);
    if (securityContext instanceof LoginSecurityContext
        && ((LoginSecurityContext)securityContext).getSubject() != null) {
        camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, 
                                               ((LoginSecurityContext)securityContext).getSubject());
    } else if (securityContext != null && securityContext.getUserPrincipal() != null) {
        Subject subject = new Subject();
        subject.getPrincipals().add(securityContext.getUserPrincipal());
        camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
    }
}
项目:Camel    文件:DefaultCxfRsBinding.java   
protected void copyOperationResourceInfoStack(org.apache.cxf.message.Message cxfMessage, Message camelMessage) {
    OperationResourceInfoStack stack = cxfMessage.get(OperationResourceInfoStack.class);
    if (stack != null) {
        // make a copy of the operation resource info for looking up the sub resource location
        OperationResourceInfoStack copyStack = (OperationResourceInfoStack)stack.clone();
        camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_OPERATION_RESOURCE_INFO_STACK, copyStack);

    }
}
项目:Camel    文件:MyProcessor.java   
public void process(Exchange exchange) throws Exception {
    Thread.sleep(4000);
    Message in = exchange.getIn();
    // Get the parameter list
    List<?> parameter = in.getBody(List.class);
    // Get the operation name
    String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
    Object result = operation + " " + (String)parameter.get(0);
    exchange.getOut().setBody(result);
}
项目:Camel    文件:CxfCustomizedExceptionTest.java   
@Test
public void testInvokingServiceFromCamel() throws Exception {
    Object result = template.sendBodyAndHeader("direct:start", ExchangePattern.InOut, "hello world", CxfConstants.OPERATION_NAME, "echo");
    assertTrue("Exception is not instance of SoapFault", result instanceof SoapFault);
    assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)result).getDetail().getTextContent());
    assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)result).getFaultCode().toString());
}
项目:Camel    文件:CxfSpringCustomizedExceptionTest.java   
@Test
public void testInvokingServiceFromCamel() throws Exception {
    try {
        template.sendBodyAndHeader("direct:start", ExchangePattern.InOut, "hello world", CxfConstants.OPERATION_NAME, "echo");
        fail("Should have thrown an exception");
    } catch (Exception ex) {
        Throwable result = ex.getCause();
        assertTrue("Exception is not instance of SoapFault", result instanceof SoapFault);
        assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)result).getDetail().getTextContent());
        assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)result).getFaultCode().toString());
    }

}
项目:Camel    文件:DefaultCxfBindingTest.java   
@Test
public void testPopulateCxfRequestFromExchange() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> requestContext = new HashMap<String, Object>();

    exchange.getIn().setHeader("soapAction", "urn:hello:world");
    exchange.getIn().setHeader("MyFruitHeader", "peach");
    exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
    exchange.getIn().addAttachment("att-1", new DataHandler(new FileDataSource("pom.xml")));

    cxfBinding.populateCxfRequestFromExchange(cxfExchange, exchange, requestContext);

    // check the protocol headers
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)requestContext.get(Message.PROTOCOL_HEADERS));
    assertNotNull(headers);
    assertEquals(3, headers.size());

    verifyHeader(headers, "soapaction", "urn:hello:world");
    verifyHeader(headers, "SoapAction", "urn:hello:world");
    verifyHeader(headers, "SOAPAction", "urn:hello:world");
    verifyHeader(headers, "myfruitheader", "peach");
    verifyHeader(headers, "myFruitHeader", "peach");
    verifyHeader(headers, "MYFRUITHEADER", "peach");
    verifyHeader(headers, "MyBrewHeader", Arrays.asList("cappuccino", "espresso"));

    Set<Attachment> attachments 
        = CastUtils.cast((Set<?>)requestContext.get(CxfConstants.CAMEL_CXF_ATTACHMENTS));
    assertNotNull(attachments);
    assertNotNull(attachments.size() == 1);
    Attachment att = attachments.iterator().next();
    assertEquals("att-1", att.getId());
}
项目:Camel    文件:DefaultCxfBindingTest.java   
@Test
public void testPopupalteExchangeFromCxfResponse() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> responseContext = new HashMap<String, Object>();
    responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
    headers.put("Content-Length", Arrays.asList("241"));
    responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    cxfExchange.setInMessage(cxfMessage);

    Set<Attachment> attachments = new HashSet<Attachment>();
    attachments.add(new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml"))));
    cxfMessage.setAttachments(attachments);

    cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);

    Map<String, Object> camelHeaders = exchange.getOut().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals(responseContext, camelHeaders.get(Client.RESPONSE_CONTEXT));

    Map<String, DataHandler> camelAttachments = exchange.getOut().getAttachments();
    assertNotNull(camelAttachments);
    assertNotNull(camelAttachments.get("att-1"));
}
项目:Camel    文件:DefaultCxfBindingTest.java   
@Test
public void testPopupalteExchangeFromCxfRequest() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
    headers.put("Content-Length", Arrays.asList("241"));
    headers.put("soapAction", Arrays.asList("urn:hello:world"));
    headers.put("myfruitheader", Arrays.asList("peach"));
    headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
    cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);

    Set<Attachment> attachments = new HashSet<Attachment>();
    attachments.add(new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml"))));
    cxfMessage.setAttachments(attachments);

    cxfExchange.setInMessage(cxfMessage);

    cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange);

    Map<String, Object> camelHeaders = exchange.getIn().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals("urn:hello:world", camelHeaders.get("soapaction"));
    assertEquals("urn:hello:world", camelHeaders.get("SoapAction"));
    assertEquals("text/xml;charset=UTF-8", camelHeaders.get("content-type"));
    assertEquals("241", camelHeaders.get("content-length"));
    assertEquals("peach", camelHeaders.get("MyFruitHeader"));
    assertEquals(Arrays.asList("cappuccino", "espresso"), camelHeaders.get("MyBrewHeader"));

    Map<String, DataHandler> camelAttachments = exchange.getIn().getAttachments();
    assertNotNull(camelAttachments);
    assertNotNull(camelAttachments.get("att-1"));

}
项目:Camel    文件:CxfMessageHeadersRelayTest.java   
protected void doTestInOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
    // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<Object> params = new ArrayList<Object>();
    Me me = new Me();
    me.setFirstName("john");
    me.setLastName("Doh");

    params.add(me);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inOutOfBandHeader");

    List<Header> headers = buildOutOfBandHeaderList(false);
    Map<String, Object> requestContext = new HashMap<String, Object>();
    requestContext.put(Header.HEADER_LIST, headers);
    senderExchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);

    Exchange exchange = template.send(producerUri, senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    MessageContentsList result = (MessageContentsList)out.getBody();
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    assertTrue("Expected the out of band header to propagate but it didn't", 
               result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass"));

}
项目:Camel    文件:CxfMessageHeadersRelayTest.java   
public void doTestInOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
    // START SNIPPET: sending
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<Object> params = new ArrayList<Object>();
    Me me = new Me();
    me.setFirstName("john");
    me.setLastName("Doh");

    params.add(me);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inoutOutOfBandHeader");

    List<Header> inHeaders = buildOutOfBandHeaderList(false);
    Map<String, Object> requestContext = new HashMap<String, Object>();
    requestContext.put(Header.HEADER_LIST, inHeaders);
    senderExchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);

    Exchange exchange = template.send(producerUri, senderExchange);

    org.apache.camel.Message out = exchange.getOut();
    MessageContentsList result = (MessageContentsList)out.getBody();
    assertTrue("Expected the out of band header to propagate but it didn't", 
               result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass"));
    Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
    assertNotNull(responseContext);
    validateReturnedOutOfBandHeader(responseContext);
}
项目:Camel    文件:CxfRsHeaderFilterStrategyTest.java   
@Test
public void testFilterCamelHeaders() throws Exception {
    HeaderFilterStrategy filter = new CxfRsHeaderFilterStrategy();
    assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders(Exchange.CHARSET_NAME, "just a test", null));
    assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, "just a test", null));
    assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders("org.apache.camel.such.Header", "just a test", null));
    assertFalse("Get a wrong filtered result", filter.applyFilterToCamelHeaders("camel.result", "just a test", null));
}
项目:Camel    文件:CxfProducerRouterTest.java   
@Test
public void testCannotSendRequest() throws Exception {
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(1);

    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    final List<String> params = new ArrayList<String>();
    // Prepare the request message for the camel-cxf procedure
    params.add(TEST_MESSAGE);
    senderExchange.getIn().setBody(params);
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);
    template.send("direct:start", senderExchange);
    error.assertIsSatisfied();
}