Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * JBoss, Home of Professional Open Source 
   * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
   * as indicated by the @author tags. All rights reserved. 
   * See the copyright.txt in the distribution for a 
   * full listing of individual contributors.
   *
   * This copyrighted material is made available to anyone wishing to use, 
   * modify, copy, or redistribute it subject to the terms and conditions 
  * of the GNU Lesser General Public License, v. 2.1. 
  * This program is distributed in the hope that it will be useful, but WITHOUT A 
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details. 
  * You should have received a copy of the GNU Lesser General Public License, 
  * v.2.1 along with this distribution; if not, write to the Free Software 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
  * MA  02110-1301, USA.
  */
  
 package org.switchyard.component.soap;
 
 import java.net.URL;
 
 import  javax.wsdl.Port;
 import  javax.wsdl.WSDLException;
 
Handles invoking external Webservice endpoints.

Author(s):
Magesh Kumar B <mageshbk@jboss.com> (C) 2011 Red Hat Inc.
 
 public class OutboundHandler extends BaseServiceHandler {
 
     private static final Logger LOGGER = Logger.getLogger(OutboundHandler.class);
 
     private final SOAPBindingModel _config;
     private final MessageComposer<SOAPMessage_messageComposer;
 
     private Dispatch<SOAPMessage_dispatcher;
     private Port _port;

    
Constructor.

Parameters:
config the configuration settings
 
     public OutboundHandler(final SOAPBindingModel config) {
          = config;
          = SOAPComposition.getMessageComposer(config);
     }

    
Start lifecycle.

Throws:
WebServiceConsumeException If unable to load the WSDL
 
     public void start() throws WebServiceConsumeException {
         //XXX: REMOVE THIS SYNCHRONIZED: once threading issues in AS7 WS are fixed
         synchronized (BaseWebService.class) {
         if ( == null) {
             ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
             try {
                 PortName portName = .getPort();
                 javax.wsdl.Service wsdlService = WSDLUtil.getService(.getWsdl(), portName);
                  = WSDLUtil.getPort(wsdlServiceportName);
                 // Update the portName
                 portName.setServiceQName(wsdlService.getQName());
                 portName.setName(.getName());
 
                 URL wsdlUrl = WSDLUtil.getURL(.getWsdl());
                 .info("Creating dispatch with WSDL " + wsdlUrl);
                 // make sure we don't pollute the class loader used by the WS subsystem
                 Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
                 Service service = Service.create(wsdlUrlportName.getServiceQName());
                  = service.createDispatch(portName.getPortQName(), SOAPMessage.class..new AddressingFeature(falsefalse));
                 // this does not return a proper qualified Fault element and has no Detail so deferring for now
                 // BindingProvider bp = (BindingProvider) _dispatcher;
                 // bp.getRequestContext().put("jaxws.response.throwExceptionIfSOAPFault", Boolean.FALSE);
 
             } catch (MalformedURLException e) {
                 throw new WebServiceConsumeException(e);
             } catch (WSDLException wsdle) {
                 throw new WebServiceConsumeException(wsdle);
            } finally {
                Thread.currentThread().setContextClassLoader(origLoader);
            }
        }
        }
    }

    
Stop lifecycle.
    public void stop() {
    }

    
The handler method that invokes the actual Webservice when the component is used as a WS consumer.

Parameters:
exchange the Exchange
Throws:
HandlerException handler exception
    @Override
    public void handleMessage(final Exchange exchangethrows HandlerException {
        try {
            if (. == null) {
                throw new SOAPException("Failed to instantiate SOAP Message Factory");
            }
            SOAPMessage request;
            try {
                request = .decompose(exchange..createMessage());
            } catch (Exception e) {
                throw e instanceof SOAPException ? (SOAPException)e : new SOAPException(e);
            }
            
            if (.isTraceEnabled()) {
                .trace("Request:[" + SOAPUtil.soapMessageToString(request) + "]");
            }
            
            SOAPMessage response = invokeService(request);
            if (response != null) {
                Message message;
                try {
                    message = .compose(responseexchangetrue);
                } catch (Exception e) {
                    throw e instanceof SOAPException ? (SOAPException)e : new SOAPException(e);
                }
                exchange.send(message);
            }
            
            if (.isTraceEnabled()) {
                .trace("Response:[" + SOAPUtil.soapMessageToString(response) + "]");
            }
            
        } catch (SOAPException se) {
            throw new HandlerException("Unexpected exception handling SOAP Message"se);
        }
    }

    
Invoke Webservice via Dispatch API

Parameters:
soapMessage the SOAP request
Returns:
the SOAP response
Throws:
SOAPException If a Dispatch could not be created based on the SOAP message.
    private SOAPMessage invokeService(final SOAPMessage soapMessagethrows SOAPException {
        SOAPMessage response = null;
        try {
            String firstBodyElement = SOAPUtil.getFirstBodyElement(soapMessage);
            if (WSDLUtil.isOneWay(firstBodyElement)) {
                .invokeOneWay(soapMessage);
                //return empty response
            } else {
                response = .invoke(soapMessage);
            }
        } catch (SOAPFaultException sfex) {
            response = SOAPUtil.generateFault(sfex);
        } catch (Exception ex) {
            throw new SOAPException("Cannot process SOAP request"ex);
        }
        return response;
    }
New to GrepCode? Check out our FAQ X