|
Apache CXF example source code file (ServiceInvokerInterceptor.java)
The Apache CXF ServiceInvokerInterceptor.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.interceptor; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.FutureTask; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageContentsList; import org.apache.cxf.message.MessageImpl; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.apache.cxf.service.Service; import org.apache.cxf.service.invoker.Invoker; /** * Invokes a Binding's invoker with the <code>INVOCATION_INPUT from * the Exchange. * @author Dan Diephouse */ public class ServiceInvokerInterceptor extends AbstractPhaseInterceptor<Message> { public ServiceInvokerInterceptor() { super(Phase.INVOKE); } public void handleMessage(final Message message) { final Exchange exchange = message.getExchange(); final Endpoint endpoint = exchange.get(Endpoint.class); final Service service = endpoint.getService(); final Invoker invoker = service.getInvoker(); Runnable invocation = new Runnable() { public void run() { Exchange runableEx = message.getExchange(); Object result = invoker.invoke(runableEx, getInvokee(message)); if (!exchange.isOneWay()) { Endpoint ep = exchange.get(Endpoint.class); Message outMessage = runableEx.getOutMessage(); if (outMessage == null) { outMessage = new MessageImpl(); outMessage.setExchange(exchange); outMessage = ep.getBinding().createMessage(outMessage); exchange.setOutMessage(outMessage); } copyJaxwsProperties(message, outMessage); if (result != null) { MessageContentsList resList = null; if (result instanceof MessageContentsList) { resList = (MessageContentsList)result; } else if (result instanceof List) { resList = new MessageContentsList((List)result); } else if (result.getClass().isArray()) { resList = new MessageContentsList((Object[])result); } else { outMessage.setContent(Object.class, result); } if (resList != null) { outMessage.setContent(List.class, resList); } } } } }; Executor executor = getExecutor(endpoint); if (exchange.get(Executor.class) == executor) { // already executing on the appropriate executor invocation.run(); } else { exchange.put(Executor.class, executor); FutureTask<Object> o = new FutureTask |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.