Package org.servicemix.components.jaxws

Source Code of org.servicemix.components.jaxws.JAXWSComponent

/**
*
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
*
* Licensed 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.servicemix.components.jaxws;

import java.util.Iterator;

import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.InOptionalOut;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.ws.handler.MessageContext;

import org.servicemix.components.AbstractDeployableComponent;
import org.servicemix.components.ServiceUnit;
import org.servicemix.jbi.NoInMessageAvailableException;

import com.sun.xml.ws.handler.MessageContextImpl;
import com.sun.xml.ws.server.RuntimeEndpointInfo;
import com.sun.xml.ws.server.Tie;
import com.sun.xml.ws.spi.runtime.WSConnection;
import com.sun.xml.ws.spi.runtime.WebServiceContext;

public class JAXWSComponent extends AbstractDeployableComponent {

    @Override
    protected ServiceUnit doDeploy(String serviceUnitName, String serviceUnitRootPath) throws Exception {
        return new JAXWSServiceUnit(this, serviceUnitName, serviceUnitRootPath);
    }

    @Override
    protected void process(MessageExchange me) throws Exception {
        if (me.getStatus() == ExchangeStatus.DONE) {
            return;
        }
        if (me.getStatus() == ExchangeStatus.ERROR) {
            me.setStatus(ExchangeStatus.DONE);
            getContext().getDeliveryChannel().send(me);
        }
        try {
            ServiceEndpoint se = me.getEndpoint();
            RuntimeEndpointInfo rtEndpointInfo = null;
            for (Iterator it = serviceUnits.values().iterator(); it.hasNext();) {
                JAXWSServiceUnit su = (JAXWSServiceUnit) it.next();
                RuntimeEndpointInfo rei = su.getRuntimeEndpointInfo(se.getServiceName(), se.getEndpointName());
                if (rei != null) {
                    rtEndpointInfo = rei;
                    break;
                }
            }
            if (rtEndpointInfo == null) {
                throw new MessagingException("Could not find endpoint for " + se);
            }
           
            NormalizedMessage in = me.getMessage("in");
            if (in == null) {
                throw new NoInMessageAvailableException(me);
            }
            NormalizedMessage out = me.createMessage();
            Tie tie = new Tie();
            WSConnection con = new WSConnectionDelegate(in, out);
            MessageContext msgCtxt = new MessageContextImpl();
            WebServiceContext wsContext = rtEndpointInfo.getWebServiceContext();
            wsContext.setMessageContext(msgCtxt);
            tie.handle(con, rtEndpointInfo);
            if (isInAndOut(me)) {
                me.setMessage(out, "out");
            } else {
                me.setStatus(ExchangeStatus.DONE);
            }
        } catch (Exception e) {
            me.setStatus(ExchangeStatus.ERROR);
            me.setError(e);
            logger.debug("Exception catch", e);
        } catch (Throwable t) {
            me.setStatus(ExchangeStatus.ERROR);
            me.setError(new Exception(t));
            logger.info("Throwable catch", t);
        } finally {
            getContext().getDeliveryChannel().send(me);
        }
    }

    protected boolean isInAndOut(MessageExchange exchange) {
        return exchange instanceof InOut || exchange instanceof InOptionalOut;
    }
}
TOP

Related Classes of org.servicemix.components.jaxws.JAXWSComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.