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