1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.client.api; 36 37 import java.util.Properties; 38 39 import org.ogf.graap.wsag.api.security.ISecurityProperties; 40 import org.ogf.graap.wsag.api.security.SecurityProperties; 41 import org.w3.x2005.x08.addressing.EndpointReferenceType; 42 43 /** 44 * Interface of a remote client. A remote client encapsulates the client object used for communicating with 45 * the server application. Different remote technologies can be supported, i.e. REST (HTTP) or SOAP based 46 * services. 47 * 48 * @author Oliver Waeldrich 49 */ 50 public class RemoteClient 51 { 52 53 private Properties properties = new Properties(); 54 55 private ISecurityProperties securityProperties = new SecurityProperties( null ); 56 57 private final EndpointReferenceType remoteReference; 58 59 private boolean isUsingTrace = false; 60 61 /** 62 * Constructs a new remote client with the given reference. 63 * 64 * @param reference 65 * the remote reference 66 */ 67 public RemoteClient( EndpointReferenceType reference ) 68 { 69 remoteReference = reference; 70 } 71 72 /** 73 * Constructs a new remote client with the given remote reference. 74 * 75 * @param reference 76 * the remote reference 77 */ 78 public RemoteClient( String reference ) 79 { 80 remoteReference = EndpointReferenceType.Factory.newInstance(); 81 remoteReference.addNewAddress().setStringValue( reference ); 82 } 83 84 /** 85 * Constructs a new remote client with the given properties and reference. 86 * 87 * @param reference 88 * the remote reference 89 * 90 * @param properties 91 * the client properties 92 * 93 * @param securityProperties 94 * the security properties associated with the remote client 95 */ 96 public RemoteClient( EndpointReferenceType reference, Properties properties, 97 ISecurityProperties securityProperties ) 98 { 99 remoteReference = reference; 100 this.properties = properties; 101 this.securityProperties = securityProperties; 102 } 103 104 /** 105 * Constructs a new remote client with the given properties and reference. 106 * 107 * @param reference 108 * the remote reference 109 * 110 * @param properties 111 * the client properties 112 * 113 * @param securityProperties 114 * the security properties associated with the remote client 115 */ 116 public RemoteClient( String reference, Properties properties, ISecurityProperties securityProperties ) 117 { 118 this( reference ); 119 this.properties = properties; 120 this.securityProperties = securityProperties; 121 } 122 123 /** 124 * Returns the security properties used by the web-service client. 125 * 126 * @return the security properties for this client 127 */ 128 public ISecurityProperties getSecurityProperties() 129 { 130 return securityProperties; 131 } 132 133 /** 134 * Sets the security properties used by the web-service client. 135 * 136 * @param securityProperties 137 * the security properties for this client 138 */ 139 public void setSecurityProperties( ISecurityProperties securityProperties ) 140 { 141 this.securityProperties = securityProperties; 142 } 143 144 /** 145 * Returns the properties used by the web-service client. 146 * 147 * @return a list of properties associated with the client 148 */ 149 public Properties getProperties() 150 { 151 return properties; 152 } 153 154 /** 155 * Sets the properties used for the web-service client. 156 * 157 * @param properties 158 * Sets the properties for this client 159 */ 160 public void setProperties( Properties properties ) 161 { 162 this.properties = properties; 163 } 164 165 /** 166 * Returns the endpoint of the client instance. 167 * 168 * @return Returns the endpoint reference for this WS resource. 169 */ 170 public EndpointReferenceType getRemoteReference() 171 { 172 return remoteReference; 173 } 174 175 /** 176 * Determines whether or not a client prints the web-service messages to the console. 177 * 178 * @return true, if the web service client traces the incoming/outgoing messages. 179 */ 180 public boolean isUsingTrace() 181 { 182 return isUsingTrace; 183 } 184 185 /** 186 * Sets the clients trace mode. 187 * 188 * @param trace 189 * true, if the web service client should traces incoming/outgoing messages. 190 */ 191 public void setTrace( boolean trace ) 192 { 193 isUsingTrace = trace; 194 } 195 196 }