Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UserInfoEndpointURIBuilder |
|
| 11.0;11 |
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.endpoint; | |
8 | ||
9 | import org.mule.api.endpoint.MalformedEndpointException; | |
10 | ||
11 | import java.net.URI; | |
12 | import java.util.Properties; | |
13 | ||
14 | /** | |
15 | * <code>UserInfoEndpointBuilder</code> builds an endpoint with the userinfo and | |
16 | * host details. This endpoint builder is used where endpoints as of the form : | |
17 | * xxx://ross:secret@host:1000 | |
18 | */ | |
19 | 0 | public class UserInfoEndpointURIBuilder extends AbstractEndpointURIBuilder |
20 | { | |
21 | //TODO THis endpoint builder is redundant I think. We should be able to use the URL endpoint builder. | |
22 | //It depends on where deriving classes can work with the URL endpoint builder, but there are a lot of similarities | |
23 | protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException | |
24 | { | |
25 | // Added by Lajos 2006-12-14 per Ross | |
26 | 0 | if (uri.getHost() == null) |
27 | { | |
28 | 0 | if (props.getProperty("address") == null) |
29 | { | |
30 | 0 | throw new MalformedEndpointException(uri.toString()); |
31 | } | |
32 | else | |
33 | { | |
34 | 0 | return; |
35 | } | |
36 | } | |
37 | ||
38 | // Check and handle '@' symbols in the user info | |
39 | 0 | address = uri.getHost(); |
40 | 0 | int a = address.indexOf("."); |
41 | 0 | int b = (a == -1 ? -1 : address.indexOf(".", a + 1)); |
42 | 0 | if (b > -1) |
43 | { | |
44 | 0 | address = address.substring(a + 1); |
45 | } | |
46 | ||
47 | 0 | if (uri.getPort() != -1) |
48 | { | |
49 | // set the endpointUri to be a proper url if host and port are set | |
50 | 0 | this.address += ":" + uri.getPort(); |
51 | } | |
52 | ||
53 | 0 | if (userInfo != null) |
54 | { | |
55 | 0 | int x = userInfo.indexOf(":"); |
56 | 0 | if (x > -1) |
57 | { | |
58 | 0 | String user = userInfo.substring(0, x); |
59 | 0 | if (user.indexOf("@") > -1) |
60 | { | |
61 | 0 | address = user; |
62 | } | |
63 | else | |
64 | { | |
65 | 0 | address = user + "@" + address; |
66 | } | |
67 | 0 | } |
68 | else | |
69 | { | |
70 | 0 | if (userInfo.indexOf("@") > -1) |
71 | { | |
72 | 0 | address = userInfo; |
73 | } | |
74 | else | |
75 | { | |
76 | 0 | address = userInfo + "@" + address; |
77 | } | |
78 | } | |
79 | } | |
80 | 0 | } |
81 | } |