Coverage Report - org.mule.transport.xmpp.XmppEndpointURIBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppEndpointURIBuilder
0%
0/16
0%
0/4
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.transport.xmpp;
 8  
 
 9  
 import org.mule.api.endpoint.MalformedEndpointException;
 10  
 import org.mule.endpoint.UserInfoEndpointURIBuilder;
 11  
 import org.mule.transport.xmpp.i18n.XmppMessages;
 12  
 
 13  
 import java.net.URI;
 14  
 import java.util.Properties;
 15  
 
 16  
 /**
 17  
  * This endpoint builder ensures that a path is set on the URI as the path is the message type.
 18  
  * 
 19  
  */
 20  0
 public class XmppEndpointURIBuilder extends UserInfoEndpointURIBuilder
 21  
 {
 22  
     @Override
 23  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 24  
     {
 25  0
         checkXmppMessageType(uri);
 26  0
         checkRecipient(uri);
 27  0
         super.setEndpoint(uri, props);
 28  0
     }
 29  
 
 30  
     private void checkXmppMessageType(URI uri) throws MalformedEndpointException
 31  
     {
 32  
         // the XMPP message type is stored in the host of the URL
 33  0
         String host = uri.getHost();
 34  
         
 35  0
         if (host.length() == 0)
 36  
         {
 37  0
             throw new MalformedEndpointException(XmppMessages.noMessageTypeInUri(), uri.toString());
 38  
         }
 39  
         
 40  
         try
 41  
         {
 42  0
             XmppMessageType.valueOf(host);
 43  
         }
 44  0
         catch (IllegalArgumentException e)
 45  
         {
 46  0
             throw new MalformedEndpointException(XmppMessages.invalidMessageTypeInUri(), 
 47  
                 uri.toString());
 48  0
         }
 49  0
     }
 50  
 
 51  
     private void checkRecipient(URI uri) throws MalformedEndpointException
 52  
     {
 53  
         // the recipient is stored in the path of the URL
 54  0
         if (uri.getPath().length() == 0)
 55  
         {
 56  0
             throw new MalformedEndpointException(XmppMessages.noRecipientInUri(), uri.toString());
 57  
         }        
 58  0
     }
 59  
 }