Coverage Report - org.mule.module.cxf.endpoint.WsdlCxfEndpointBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
WsdlCxfEndpointBuilder
0%
0/31
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: WsdlCxfEndpointBuilder.java 19266 2010-09-01 01:30:16Z ddossot $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.module.cxf.endpoint;
 12  
 
 13  
 import java.util.ArrayList;
 14  
 import java.util.Arrays;
 15  
 
 16  
 import org.mule.api.MuleContext;
 17  
 import org.mule.api.endpoint.EndpointException;
 18  
 import org.mule.api.endpoint.InboundEndpoint;
 19  
 import org.mule.api.endpoint.OutboundEndpoint;
 20  
 import org.mule.api.lifecycle.InitialisationException;
 21  
 import org.mule.api.processor.MessageProcessor;
 22  
 import org.mule.endpoint.AbstractMetaEndpointBuilder;
 23  
 import org.mule.endpoint.EndpointURIEndpointBuilder;
 24  
 import org.mule.module.cxf.builder.WsdlClientMessageProcessorBuilder;
 25  
 import org.mule.module.cxf.config.FlowConfiguringMessageProcessor;
 26  
 
 27  
 public class WsdlCxfEndpointBuilder extends AbstractMetaEndpointBuilder
 28  
 {
 29  
 
 30  
     private final String wsdlAddress;
 31  
 
 32  
     public WsdlCxfEndpointBuilder(EndpointURIEndpointBuilder global) throws EndpointException
 33  
     {
 34  0
         super(global);
 35  
 
 36  0
         this.wsdlAddress = getEndpointAddressWithoutMetaScheme(global.getEndpointBuilder().toString());
 37  0
         this.uriBuilder = new EndpointURIEndpointBuilder(wsdlAddress, muleContext).getEndpointBuilder();
 38  0
     }
 39  
 
 40  
     public WsdlCxfEndpointBuilder(String address, MuleContext muleContext)
 41  
     {
 42  0
         super(getAddressWithoutQuery(getEndpointAddressWithoutMetaScheme(address)), muleContext);
 43  0
         this.wsdlAddress = getEndpointAddressWithoutMetaScheme(address);
 44  0
     }
 45  
 
 46  
     @Override
 47  
     public InboundEndpoint buildInboundEndpoint() throws EndpointException, InitialisationException
 48  
     {
 49  0
         throw new UnsupportedOperationException("Inbound meta CXF endpoints not supported");
 50  
     }
 51  
 
 52  
     @Override
 53  
     public OutboundEndpoint buildOutboundEndpoint() throws EndpointException, InitialisationException
 54  
     {
 55  0
         final WsdlClientMessageProcessorBuilder builder = new WsdlClientMessageProcessorBuilder();
 56  0
         builder.setMuleContext(muleContext);
 57  0
         builder.setWsdlLocation(wsdlAddress);
 58  0
         builder.setOperation(getOperation());
 59  
 
 60  
         try
 61  
         {
 62  
             // List must be mutable as it gets cleared on Mule shutdown
 63  0
             messageProcessors = new ArrayList<MessageProcessor>(
 64  
                 Arrays.asList(new FlowConfiguringMessageProcessor(builder)));
 65  
         }
 66  0
         catch (final Exception e)
 67  
         {
 68  0
             throw new EndpointException(e);
 69  0
         }
 70  
 
 71  0
         return super.buildOutboundEndpoint();
 72  
     }
 73  
 
 74  
     private String getOperation()
 75  
     {
 76  0
         String query = wsdlAddress;
 77  0
         final int idx = wsdlAddress.lastIndexOf('?');
 78  0
         if (idx != -1)
 79  
         {
 80  0
             query = wsdlAddress.substring(idx + 1);
 81  
         }
 82  
         else
 83  
         {
 84  0
             return null;
 85  
         }
 86  
 
 87  0
         final String[] params = query.split("&");
 88  0
         for (final String p : params)
 89  
         {
 90  0
             if (p.startsWith("method="))
 91  
             {
 92  0
                 return p.substring(7);
 93  
             }
 94  
         }
 95  0
         return null;
 96  
     }
 97  
 
 98  
     private static String getAddressWithoutQuery(String string)
 99  
     {
 100  0
         final int idx = string.indexOf('?');
 101  0
         if (idx != -1)
 102  
         {
 103  0
             string = string.substring(0, idx);
 104  
         }
 105  0
         return string;
 106  
     }
 107  
 
 108  
 }