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