当前位置: 首页>>代码示例>>Java>>正文


Java Exchange类代码示例

本文整理汇总了Java中org.apache.cxf.message.Exchange的典型用法代码示例。如果您正苦于以下问题:Java Exchange类的具体用法?Java Exchange怎么用?Java Exchange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Exchange类属于org.apache.cxf.message包,在下文中一共展示了Exchange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureMessage2

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
@Test
public void configureMessage2() throws IllegalArgumentException {
	final UserImportEntry entry = Mockito.mock(UserImportEntry.class);
	Mockito.when(entry.getId()).thenThrow(new RuntimeException());
	final BatchTaskVo<UserImportEntry> importTask = new BatchTaskVo<>();
	importTask.setEntries(Collections.singletonList(entry));

	final Message message = Mockito.mock(Message.class);
	final UserFullLdapTask task = new UserFullLdapTask() {
		@Override
		protected Message getMessage() {
			return message;
		}

	};
	final Exchange exchange = Mockito.mock(Exchange.class);
	Mockito.when(message.getExchange()).thenReturn(exchange);
	final Endpoint endpoint = Mockito.mock(Endpoint.class);
	Mockito.when(exchange.getEndpoint()).thenReturn(endpoint);
	Mockito.when(endpoint.get("org.apache.cxf.jaxrs.provider.ServerProviderFactory")).thenReturn(ServerProviderFactory.getInstance());

	task.configure(importTask);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:24,代码来源:UserFullLdapTaskTest.java

示例2: getMockMessage

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
/**
 * Creates a mock message that is destined for a method called "test"on
 */
private Message getMockMessage() throws NoSuchMethodException {
    Message message = mock(Message.class);
    Exchange exchange = mock(Exchange.class);
    BindingOperationInfo bindingOperationInfo = mock(BindingOperationInfo.class);
    Service service = mock(Service.class);
    MethodDispatcher methodDispatcher = mock(MethodDispatcher.class);
    Method method = TestClass.class.getMethod("test");

    when(message.getExchange()).thenReturn(exchange);
    when(exchange.get(BindingOperationInfo.class)).thenReturn(bindingOperationInfo);
    when(exchange.get(Service.class)).thenReturn(service);
    when(service.get(MethodDispatcher.class.getName())).thenReturn(methodDispatcher);
    when(methodDispatcher.getMethod(bindingOperationInfo)).thenReturn(method);

    return message;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:20,代码来源:CxfFunctionGuardInterceptorTest.java

示例3: testHandleMessage

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
@Test
public void testHandleMessage() throws Exception
{
    Message message = InterceptorStateHelper.getMessage( InterceptorState.SERVER_IN );
    Exchange exchange = message.getExchange();
    doReturn( message ).when( exchange ).getInMessage();
    doReturn( request ).when( message ).get( AbstractHTTPDestination.HTTP_REQUEST );
    doReturn( Common.DEFAULT_PUBLIC_SECURE_PORT ).when( request ).getLocalPort();
    doReturn( "/rest/v1/peer" ).when( request ).getRequestURI();

    interceptor.handleMessage( message );

    verify( interceptor ).handlePeerMessage( anyString(), eq( message ) );

    doReturn( "/rest/v1/env/123/" ).when( request ).getRequestURI();

    interceptor.handleMessage( message );

    verify( interceptor ).handleEnvironmentMessage( anyString(), anyString(), eq( message ) );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:ServerInInterceptorTest.java

示例4: syncInvoke

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
private Object syncInvoke(Exchange cxfExchange) {
    org.apache.camel.Exchange camelExchange = prepareCamelExchange(cxfExchange);
    try {
        try {
            LOG.trace("Processing +++ START +++");
            // send Camel exchange to the target processor
            getProcessor().process(camelExchange);
        } catch (Exception e) {
            throw new Fault(e);
        }

        LOG.trace("Processing +++ END +++");
        setResponseBack(cxfExchange, camelExchange);
    } finally {
        doneUoW(camelExchange);
    }
    // response should have been set in outMessage's content
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:CxfConsumer.java

示例5: populateExchangeFromCxfRsRequest

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
@Override
public void populateExchangeFromCxfRsRequest(Exchange cxfExchange, org.apache.camel.Exchange camelExchange,
                                             Method method, Object[] paramArray) {
    super.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
    Message in = camelExchange.getIn();
    bindHeadersFromSubresourceLocators(cxfExchange, camelExchange);
    MethodSpec spec = methodSpecCache.get(method);
    if (spec == null) {
        spec = MethodSpec.fromMethod(method);
        methodSpecCache.put(method, spec);
    }
    bindParameters(in, paramArray, spec.paramNames, spec.numberParameters);
    bindBody(in, paramArray, spec.entityIndex);
    if (spec.multipart) {
        transferMultipartParameters(paramArray, spec.multipartNames, spec.multipartTypes, in);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SimpleCxfRsBinding.java

示例6: buildResponse

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
/**
 * Builds the response for the client.
 * <p />
 * Always returns a JAX-RS {@link Response} object, which gives the user a better control on the response behaviour.
 * If the message body is already an instance of {@link Response}, we reuse it and just inject the relevant HTTP headers.
 * @param camelExchange
 * @param base
 * @return
 */
protected Object buildResponse(org.apache.camel.Exchange camelExchange, Object base) {
    Message m = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn();
    ResponseBuilder response;

    // if the body is different to Response, it's an entity; therefore, check 
    if (base instanceof Response) {
        response = Response.fromResponse((Response) base);
    } else {
        int status = m.getHeader(org.apache.camel.Exchange.HTTP_RESPONSE_CODE, Status.OK.getStatusCode(), Integer.class);
        response = Response.status(status);
        
        // avoid using the request MessageContentsList as the entity; it simply doesn't make sense
        if (base != null && !(base instanceof MessageContentsList)) {
            response.entity(base);
        }
    }

    // Compute which headers to transfer by applying the HeaderFilterStrategy, and transfer them to the JAX-RS Response
    Map<String, String> headersToPropagate = filterCamelHeadersForResponseHeaders(m.getHeaders(), camelExchange);
    for (Entry<String, String> entry : headersToPropagate.entrySet()) {
        response.header(entry.getKey(), entry.getValue());
    }
    return response.build();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:SimpleCxfRsBinding.java

示例7: filterCamelHeadersForResponseHeaders

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
/**
 * Filters the response headers that will be sent back to the client.
 * <p />
 * The {@link DefaultCxfRsBinding} doesn't filter the response headers according to the {@link HeaderFilterStrategy}, 
 * so we handle this task in this binding.
 */
protected Map<String, String> filterCamelHeadersForResponseHeaders(Map<String, Object> headers,
                                                                 org.apache.camel.Exchange camelExchange) {
    Map<String, String> answer = new HashMap<String, String>();
    for (Map.Entry<String, Object> entry : headers.entrySet()) {
        if (getHeaderFilterStrategy().applyFilterToCamelHeaders(entry.getKey(), entry.getValue(), camelExchange)) {
            continue;
        }
        // skip content-length as the simple binding with Response will set correct content-length based
        // on the entity set as the Response
        if ("content-length".equalsIgnoreCase(entry.getKey())) {
            continue;
        }
        answer.put(entry.getKey(), entry.getValue().toString());
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SimpleCxfRsBinding.java

示例8: bindHeadersFromSubresourceLocators

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
/**
 * Transfers path parameters from the full path (including ancestor subresource locators) into Camel IN Message Headers.
 */
@SuppressWarnings("unchecked")
protected void bindHeadersFromSubresourceLocators(Exchange cxfExchange, org.apache.camel.Exchange camelExchange) {
    MultivaluedMap<String, String> pathParams = (MultivaluedMap<String, String>) 
            cxfExchange.getInMessage().get(URITemplate.TEMPLATE_PARAMETERS);

    // return immediately if we have no path parameters
    if (pathParams == null || (pathParams.size() == 1 && pathParams.containsKey(URITemplate.FINAL_MATCH_GROUP))) {
        return;
    }

    Message m = camelExchange.getIn();
    for (Entry<String, List<String>> entry : pathParams.entrySet()) {
        // skip over the FINAL_MATCH_GROUP which stores the entire path
        if (URITemplate.FINAL_MATCH_GROUP.equals(entry.getKey())) {
            continue;
        }
        m.setHeader(entry.getKey(), entry.getValue().get(0));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:SimpleCxfRsBinding.java

示例9: performInvocation

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
protected Object performInvocation(Exchange cxfExchange, final Object serviceObject, Method method,
                                   Object[] paramArray) throws Exception {
    Object response = null;
    if (endpoint.isPerformInvocation()) {
        response = super.performInvocation(cxfExchange, serviceObject, method, paramArray);
    }
    paramArray = insertExchange(method, paramArray, cxfExchange);
    OperationResourceInfo ori = cxfExchange.get(OperationResourceInfo.class);        
    if (ori.isSubResourceLocator()) {
        // don't delegate the sub resource locator call to camel processor
        return method.invoke(serviceObject, paramArray);
    }
    Continuation continuation;
    if (!endpoint.isSynchronous() && (continuation = getContinuation(cxfExchange)) != null) {
        LOG.trace("Calling the Camel async processors.");
        return asyncInvoke(cxfExchange, serviceObject, method, paramArray, continuation, response);
    } else {
        LOG.trace("Calling the Camel sync processors.");
        return syncInvoke(cxfExchange, serviceObject, method, paramArray, response);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CxfRsInvoker.java

示例10: syncInvoke

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
private Object syncInvoke(Exchange cxfExchange, final Object serviceObject, Method method,
                          Object[] paramArray,
                          Object response) throws Exception {
    final org.apache.camel.Exchange camelExchange = prepareExchange(cxfExchange, method, paramArray, response);
    // we want to handle the UoW
    cxfRsConsumer.createUoW(camelExchange);

    try {
        cxfRsConsumer.getProcessor().process(camelExchange);
    } catch (Exception exception) {
        camelExchange.setException(exception);
    }

    try {
        return returnResponse(cxfExchange, camelExchange);
    } finally {
        cxfRsConsumer.doneUoW(camelExchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:CxfRsInvoker.java

示例11: prepareExchange

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
private org.apache.camel.Exchange prepareExchange(Exchange cxfExchange, Method method,
        Object[] paramArray, Object response) {
    ExchangePattern ep = ExchangePattern.InOut;
    if (method.getReturnType() == Void.class) {
        ep = ExchangePattern.InOnly;
    } 
    final org.apache.camel.Exchange camelExchange = endpoint.createExchange(ep);
    if (response != null) {
        camelExchange.getOut().setBody(response);
    }
    CxfRsBinding binding = endpoint.getBinding();
    binding.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
    
    // REVISIT: It can be done inside a binding but a propagateContext would need to be passed along as
    // the CXF in message property. Question: where should this property name be set up ? 
    if (endpoint.isPropagateContexts()) {
        camelExchange.setProperty(UriInfo.class.getName(), new UriInfoImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(Request.class.getName(), new RequestImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(HttpHeaders.class.getName(), new HttpHeadersImpl(cxfExchange.getInMessage()));
        camelExchange.setProperty(SecurityContext.class.getName(), new SecurityContextImpl(cxfExchange.getInMessage()));
    }
    
    return camelExchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CxfRsInvoker.java

示例12: returnResponse

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
private Object returnResponse(Exchange cxfExchange, org.apache.camel.Exchange camelExchange) throws Exception {
    if (camelExchange.getException() != null) {
        Throwable exception = camelExchange.getException();
        Object result = null;
        if (exception instanceof RuntimeCamelException) {
            // Unwrap the RuntimeCamelException
            if (exception.getCause() != null) {
                exception = exception.getCause();
            }
        }
        if (exception instanceof WebApplicationException) {
            result = ((WebApplicationException)exception).getResponse();
            if (result != null) {
                return result;
            } else {
                throw (WebApplicationException)exception;
            }
        } 
        //CAMEL-7357 throw out other exception to make sure the ExceptionMapper work
    }
    return endpoint.getBinding().populateCxfRsResponseFromExchange(camelExchange, cxfExchange);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CxfRsInvoker.java

示例13: setupCamelDestination

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
public CamelDestination setupCamelDestination(EndpointInfo endpointInfo, boolean send) throws IOException {
    ConduitInitiator conduitInitiator = EasyMock.createMock(ConduitInitiator.class);
    CamelDestination camelDestination = new CamelDestination(context, bus, conduitInitiator, endpointInfo);
    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {
            public void onMessage(Message m) {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                destMessage = m;
            }
        };
        camelDestination.setMessageObserver(observer);
    }
    return camelDestination;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:CamelDestinationTest.java

示例14: testExceptionForwardedToExchange

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
@Test
public void testExceptionForwardedToExchange() throws IOException {
    final RuntimeException expectedException = new RuntimeException("We simulate an exception in CXF processing");
    
    DefaultCamelContext camelContext = new DefaultCamelContext();
    CamelDestination dest = EasyMock.createMock(CamelDestination.class);
    dest.incoming(EasyMock.isA(org.apache.camel.Exchange.class));
    EasyMock.expectLastCall().andThrow(expectedException);
    EasyMock.replay(dest);
    ConsumerProcessor consumerProcessor = dest.new ConsumerProcessor();
    
    // Send our dummy exchange and check that the exception that occurred on incoming is set
    DefaultExchange exchange = new DefaultExchange(camelContext);
    consumerProcessor.process(exchange);
    Exception exc = exchange.getException();
    assertNotNull(exc);
    assertEquals(expectedException, exc);
    EasyMock.verify(dest);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:CamelDestinationTest.java

示例15: handleMessage

import org.apache.cxf.message.Exchange; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public void handleMessage(Message message) throws Fault
{
   if (binding != null) {
      Exchange ex = message.getExchange();
      if (ex.get(HandlerChainInvoker.class) == null) {
         List<Handler> hc = binding.getHandlerChain();
         if (hc.size() > 1) { //no need to sort etc if the chain is empty or has one handler only
            Collections.sort(hc, comparator);
            //install a new HandlerChainInvoker using the sorted handler chain;
            //the AbstractJAXWSHandlerInterceptor will be using this invoker
            //instead of creating a new one
            ex.put(HandlerChainInvoker.class, new HandlerChainInvoker(hc, isOutbound(message, ex)));
         }
      }
   }
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:19,代码来源:HandlerChainSortInterceptor.java


注:本文中的org.apache.cxf.message.Exchange类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。