1 /**
2 * Copyright (C) 2005-2009 Alfresco Software Limited.
3 *
4 * This file is part of the Spring Surf Extension project.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.springframework.extensions.webscripts.connector;
20
21 import java.net.MalformedURLException;
22 import java.net.URL;
23
24 import org.springframework.extensions.surf.exception.WebScriptsPlatformException;
25
26 /**
27 * Abstract base class for use by developers who wish to provide
28 * additional custom client implementations.
29 *
30 * A general purpose but very useful RemoteClient implementation
31 * is provided that should handle most HTTP related matters.
32 *
33 * Client objects manage state between the web script layer and the
34 * remote endpoint. They are "dumb" objects in the sense that they
35 * need to be set up and then fired off.
36 *
37 * Connector objects tell the Client objects what to do and when.
38 * They orchestrate the sequence of handshakes and so forth so that
39 * the end user or web script developer doesn't need to worry about the
40 * underlying mechanics of speaking to the endpoint.
41 *
42 * @author muzquiano
43 */
44 public abstract class AbstractClient implements Client
45 {
46 /**
47 * Instantiates a new abstract client.
48 *
49 * @param endpoint the endpoint
50 */
51 public AbstractClient(String endpoint)
52 {
53 this.endpoint = endpoint;
54 }
55
56 /* (non-Javadoc)
57 * @see org.alfresco.connector.Client#getEndpoint()
58 */
59 public String getEndpoint()
60 {
61 return this.endpoint;
62 }
63
64 /* (non-Javadoc)
65 * @see org.alfresco.connector.Client#getURL()
66 */
67 public URL getURL()
68 {
69 try
70 {
71 return new URL(this.endpoint);
72 }
73 catch (MalformedURLException me)
74 {
75 throw new WebScriptsPlatformException("Unable to parse endpoint as URL: " + this.endpoint);
76 }
77 }
78
79 protected String endpoint;
80 }