Coverage Report - org.mule.module.ibeans.spi.support.CallRequestEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
CallRequestEndpoint
0%
0/45
0%
0/16
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.ibeans.spi.support;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.MuleMessage;
 12  
 import org.mule.api.endpoint.EndpointBuilder;
 13  
 import org.mule.api.endpoint.MalformedEndpointException;
 14  
 import org.mule.api.transformer.Transformer;
 15  
 import org.mule.config.endpoint.AnnotatedEndpointData;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.transport.AbstractConnector;
 18  
 import org.mule.util.UriParamFilter;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.ibeans.api.channel.CHANNEL;
 28  
 
 29  
 /**
 30  
  * A dynamic inbound endpoint used for request calls defined using the {@link org.ibeans.annotation.Call} annotation.
 31  
  * Note that call requests look the same as normal call endpoints except request calls do not define any headers or payload.
 32  
  * <p/>
 33  
  * The endpoint scheme is the only part of the URI that cannot be replaced at runtime.
 34  
  *
 35  
  * @see CallOutboundEndpoint
 36  
  */
 37  
 public class CallRequestEndpoint extends DynamicRequestEndpoint
 38  
 {
 39  
     /**
 40  
      * logger used by this class
 41  
      */
 42  0
     protected transient final Log logger = LogFactory.getLog(CallRequestEndpoint.class);
 43  
 
 44  
     private static final long serialVersionUID = 1861985949279708458L;
 45  
 
 46  
     //This is a hack to create a ref to the transformers collection, then we add the transformers once the endpoint type has been
 47  
     //determined
 48  0
     private static List<Transformer> transformers = new ArrayList<Transformer>();
 49  0
     private static List<Transformer> responseTransformers = new ArrayList<Transformer>();
 50  
     
 51  0
     private UriParamFilter filter = new UriParamFilter();
 52  
 
 53  
     public CallRequestEndpoint(MuleContext context, AnnotatedEndpointData epData) throws MalformedEndpointException
 54  
     {
 55  0
         super( context, createInboundBuilder(context, epData), epData.getAddress());
 56  0
     }
 57  
 
 58  
     @Override
 59  
     protected void validateUriTemplate(String uri) throws MalformedEndpointException
 60  
     {
 61  0
         if (uri.indexOf(parser.getStyle().getPrefix()) > -1 && uri.indexOf(":") > uri.indexOf(parser.getStyle().getPrefix()))
 62  
         {
 63  0
             throw new MalformedEndpointException(CoreMessages.dynamicEndpointsMustSpecifyAScheme(), uri);
 64  
         }
 65  0
     }
 66  
 
 67  
     private static EndpointBuilder createInboundBuilder(MuleContext context, AnnotatedEndpointData epData)
 68  
     {
 69  
         try
 70  
         {
 71  0
             EndpointBuilder builder = context.getEndpointFactory().getEndpointBuilder("dynamic://null");
 72  0
             builder.setExchangePattern(epData.getMep());
 73  0
             builder.setConnector(epData.getConnector());
 74  0
             builder.setName(epData.getName());
 75  0
             builder.setProperties(epData.getProperties() == null ? new HashMap() : epData.getProperties());
 76  
 
 77  0
             return builder;
 78  
         }
 79  0
         catch (MuleException e)
 80  
         {
 81  0
             throw new RuntimeException(e);
 82  
         }
 83  
     }
 84  
 
 85  
     @Override
 86  
     protected String parseURIString(String uri, MuleMessage message)
 87  
     {
 88  
         //We do additional processing here to parse the URI template
 89  0
         Map<String, Object> props = getPropertiesForTemplate(message);
 90  
 
 91  0
         String newUriString = parser.parse(props, uri);
 92  
         //Remove optional params completely if null
 93  0
         newUriString = filter.filterParamsByValue(newUriString, CallOutboundEndpoint.NULL_PARAM);
 94  
 
 95  0
         return super.parseURIString(newUriString, message);
 96  
     }
 97  
 
 98  
     @Override
 99  
     protected Map<String, Object> getPropertiesForTemplate(MuleMessage message)
 100  
     {
 101  0
         Map<String, Object> props = (Map) message.findPropertyInAnyScope(CHANNEL.URI_PARAM_PROPERTIES, null);
 102  0
         if (props == null)
 103  
         {
 104  0
             throw new IllegalStateException(CHANNEL.URI_PARAM_PROPERTIES + " not set on message");
 105  
         }
 106  0
         return props;
 107  
     }
 108  
 
 109  
     @Override
 110  
     public List getTransformers()
 111  
     {
 112  0
         if (transformers.size() == 0)
 113  
         {
 114  
             try
 115  
             {
 116  0
                 transformers.addAll(((AbstractConnector)getConnector()).getDefaultInboundTransformers(this));
 117  0
                 for (Transformer tran : transformers)
 118  
                 {
 119  0
                     tran.setEndpoint(this);
 120  0
                     tran.setMuleContext(getMuleContext());
 121  0
                     tran.initialise();
 122  
                 }
 123  
             }
 124  0
             catch (MuleException e)
 125  
             {
 126  0
                 throw new RuntimeException(e);
 127  0
             }
 128  
         }
 129  0
         return transformers;
 130  
     }
 131  
 
 132  
     @Override
 133  
     public List getResponseTransformers()
 134  
     {
 135  0
         if (responseTransformers.size() == 0)
 136  
         {
 137  
             try
 138  
             {
 139  0
                 responseTransformers.addAll(((AbstractConnector)getConnector()).getDefaultResponseTransformers(this));
 140  0
                 for (Transformer tran : responseTransformers)
 141  
                 {
 142  0
                     tran.setEndpoint(this);
 143  0
                     tran.setMuleContext(getMuleContext());
 144  0
                     tran.initialise();
 145  
                 }
 146  
             }
 147  0
             catch (MuleException e)
 148  
             {
 149  0
                 throw new RuntimeException(e);
 150  0
             }
 151  
         }
 152  0
         return transformers;
 153  
     }
 154  
 }