gluu
公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.xdi.oxauth.service.net.HttpService クラス
org.xdi.oxauth.service.net.HttpService の継承関係図
Inheritance graph
org.xdi.oxauth.service.net.HttpService 連携図
Collaboration graph

公開メンバ関数

void init ()
 
HttpClient getHttpsClientTrustAll ()
 
HttpClient getHttpsClient ()
 
HttpClient getHttpsClient (String trustStoreType, String trustStorePath, String trustStorePassword)
 
HttpClient getHttpsClient (String trustStoreType, String trustStorePath, String trustStorePassword, String keyStoreType, String keyStorePath, String keyStorePassword)
 
HttpServiceResponse executePost (HttpClient httpClient, String uri, String authData, Map< String, String > headers, String postData, ContentType contentType)
 
HttpServiceResponse executePost (HttpClient httpClient, String uri, String authData, Map< String, String > headers, String postData)
 
HttpServiceResponse executePost (HttpClient httpClient, String uri, String authData, String postData, ContentType contentType)
 
String encodeBase64 (String value)
 
String encodeUrl (String value)
 
HttpServiceResponse executeGet (HttpClient httpClient, String requestUri, Map< String, String > headers)
 
HttpServiceResponse executeGet (HttpClient httpClient, String requestUri) throws ClientProtocolException, IOException
 
byte [] getResponseContent (HttpResponse httpResponse) throws IOException
 
void consume (HttpResponse httpResponse) throws IOException
 
String convertEntityToString (byte[] responseBytes)
 
String convertEntityToString (byte[] responseBytes, Charset charset)
 
String convertEntityToString (byte[] responseBytes, String charsetName) throws UnsupportedEncodingException
 
boolean isResponseStastusCodeOk (HttpResponse httpResponse)
 
boolean isContentTypeXml (HttpResponse httpResponse)
 
String constructServerUrl (final HttpServletRequest request)
 

非公開変数類

Logger log
 
Base64 base64
 

静的非公開変数類

static final long serialVersionUID = -2398422090669045605L
 

詳解

Provides operations with http requests

著者
Yuriy Movchan Date: 02/05/2013

関数詳解

◆ constructServerUrl()

String org.xdi.oxauth.service.net.HttpService.constructServerUrl ( final HttpServletRequest  request)
inline
272  {
273  int serverPort = request.getServerPort();
274 
275  String redirectUrl;
276  if ((serverPort == 80) || (serverPort == 443)) {
277  redirectUrl = String.format("%s://%s%s", request.getScheme(), request.getServerName(), request.getContextPath());
278  } else {
279  redirectUrl = String.format("%s://%s:%s%s", request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath());
280  }
281 
282  return redirectUrl.toLowerCase();
283  }

◆ consume()

void org.xdi.oxauth.service.net.HttpService.consume ( HttpResponse  httpResponse) throws IOException
inline
212  {
213  if ((httpResponse == null) || (httpResponse.getStatusLine().getStatusCode() != HttpResponseCodes.SC_OK)) {
214  return;
215  }
216 
217  // Consume response content
218  HttpEntity entity = httpResponse.getEntity();
219  if (entity != null) {
220  EntityUtils.consume(entity);
221  }
222  }

◆ convertEntityToString() [1/3]

String org.xdi.oxauth.service.net.HttpService.convertEntityToString ( byte []  responseBytes)
inline
224  {
225  if (responseBytes == null) {
226  return null;
227  }
228 
229  return new String(responseBytes);
230  }

◆ convertEntityToString() [2/3]

String org.xdi.oxauth.service.net.HttpService.convertEntityToString ( byte []  responseBytes,
Charset  charset 
)
inline
232  {
233  if (responseBytes == null) {
234  return null;
235  }
236 
237  return new String(responseBytes, charset);
238  }

◆ convertEntityToString() [3/3]

String org.xdi.oxauth.service.net.HttpService.convertEntityToString ( byte []  responseBytes,
String  charsetName 
) throws UnsupportedEncodingException
inline
240  {
241  if (responseBytes == null) {
242  return null;
243  }
244 
245  return new String(responseBytes, charsetName);
246  }

◆ encodeBase64()

String org.xdi.oxauth.service.net.HttpService.encodeBase64 ( String  value)
inline
149  {
150  try {
151  return new String(base64.encode((value).getBytes(Util.UTF8)), Util.UTF8);
152  } catch (UnsupportedEncodingException ex) {
153  log.error("Failed to convert '{}' to base64", value, ex);
154  }
155 
156  return null;
157  }
Logger log
Definition: HttpService.java:64
Base64 base64
Definition: HttpService.java:66

◆ encodeUrl()

String org.xdi.oxauth.service.net.HttpService.encodeUrl ( String  value)
inline
159  {
160  try {
161  return URLEncoder.encode(value, Util.UTF8);
162  } catch (UnsupportedEncodingException ex) {
163  log.error("Failed to encode url '{}'", value, ex);
164  }
165 
166  return null;
167  }
Logger log
Definition: HttpService.java:64

◆ executeGet() [1/2]

HttpServiceResponse org.xdi.oxauth.service.net.HttpService.executeGet ( HttpClient  httpClient,
String  requestUri,
Map< String, String >  headers 
)
inline
169  {
170  HttpGet httpGet = new HttpGet(requestUri);
171 
172  if (headers != null) {
173  for (Entry<String, String> headerEntry : headers.entrySet()) {
174  httpGet.setHeader(headerEntry.getKey(), headerEntry.getValue());
175  }
176  }
177 
178  try {
179  HttpResponse httpResponse = httpClient.execute(httpGet);
180 
181  return new HttpServiceResponse(httpGet, httpResponse);
182  } catch (IOException ex) {
183  log.error("Failed to execute get request", ex);
184  }
185 
186  return null;
187  }
Logger log
Definition: HttpService.java:64

◆ executeGet() [2/2]

HttpServiceResponse org.xdi.oxauth.service.net.HttpService.executeGet ( HttpClient  httpClient,
String  requestUri 
) throws ClientProtocolException, IOException
inline
189  {
190  return executeGet(httpClient, requestUri, null);
191  }
HttpServiceResponse executeGet(HttpClient httpClient, String requestUri, Map< String, String > headers)
Definition: HttpService.java:169

◆ executePost() [1/3]

HttpServiceResponse org.xdi.oxauth.service.net.HttpService.executePost ( HttpClient  httpClient,
String  uri,
String  authData,
Map< String, String >  headers,
String  postData,
ContentType  contentType 
)
inline
115  {
116  HttpPost httpPost = new HttpPost(uri);
117  if (StringHelper.isNotEmpty(authData)) {
118  httpPost.setHeader("Authorization", "Basic " + authData);
119  }
120 
121  if (headers != null) {
122  for (Entry<String, String> headerEntry : headers.entrySet()) {
123  httpPost.setHeader(headerEntry.getKey(), headerEntry.getValue());
124  }
125  }
126 
127  StringEntity stringEntity = new StringEntity(postData, contentType);
128  httpPost.setEntity(stringEntity);
129 
130  try {
131  HttpResponse httpResponse = httpClient.execute(httpPost);
132 
133  return new HttpServiceResponse(httpPost, httpResponse);
134  } catch (IOException ex) {
135  log.error("Failed to execute post request", ex);
136  }
137 
138  return null;
139  }
Logger log
Definition: HttpService.java:64

◆ executePost() [2/3]

HttpServiceResponse org.xdi.oxauth.service.net.HttpService.executePost ( HttpClient  httpClient,
String  uri,
String  authData,
Map< String, String >  headers,
String  postData 
)
inline
141  {
142  return executePost(httpClient, uri, authData, headers, postData, null);
143  }
HttpServiceResponse executePost(HttpClient httpClient, String uri, String authData, Map< String, String > headers, String postData, ContentType contentType)
Definition: HttpService.java:115

◆ executePost() [3/3]

HttpServiceResponse org.xdi.oxauth.service.net.HttpService.executePost ( HttpClient  httpClient,
String  uri,
String  authData,
String  postData,
ContentType  contentType 
)
inline
145  {
146  return executePost(httpClient, uri, authData, null, postData, contentType);
147  }
HttpServiceResponse executePost(HttpClient httpClient, String uri, String authData, Map< String, String > headers, String postData, ContentType contentType)
Definition: HttpService.java:115

◆ getHttpsClient() [1/3]

HttpClient org.xdi.oxauth.service.net.HttpService.getHttpsClient ( )
inline
95  {
96  HttpClient httpClient = new SslDefaultHttpClient();
97 
98  return httpClient;
99  }

◆ getHttpsClient() [2/3]

HttpClient org.xdi.oxauth.service.net.HttpService.getHttpsClient ( String  trustStoreType,
String  trustStorePath,
String  trustStorePassword 
)
inline
101  {
102  HttpClient httpClient = new SslDefaultHttpClient(trustStoreType, trustStorePath, trustStorePassword);
103 
104  return httpClient;
105  }

◆ getHttpsClient() [3/3]

HttpClient org.xdi.oxauth.service.net.HttpService.getHttpsClient ( String  trustStoreType,
String  trustStorePath,
String  trustStorePassword,
String  keyStoreType,
String  keyStorePath,
String  keyStorePassword 
)
inline
108  {
109  HttpClient httpClient = new SslDefaultHttpClient(trustStoreType, trustStorePath, trustStorePassword,
110  keyStoreType, keyStorePath, keyStorePassword);
111 
112  return httpClient;
113  }

◆ getHttpsClientTrustAll()

HttpClient org.xdi.oxauth.service.net.HttpService.getHttpsClientTrustAll ( )
inline
73  {
74  try {
75  SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){
76  @Override
77  public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
78  return true;
79  }
80  }, new AllowAllHostnameVerifier());
81 
82  PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
83 
84  SchemeRegistry registry = new SchemeRegistry();
85  registry.register(new Scheme("http", 80, psf));
86  registry.register(new Scheme("https", 443, sf));
87  ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
88  return new DefaultHttpClient(ccm);
89  } catch (Exception ex) {
90  log.error("Failed to create TrustAll https client", ex);
91  return new DefaultHttpClient();
92  }
93  }
Logger log
Definition: HttpService.java:64

◆ getResponseContent()

byte [] org.xdi.oxauth.service.net.HttpService.getResponseContent ( HttpResponse  httpResponse) throws IOException
inline
193  {
194  if ((httpResponse == null) || (httpResponse.getStatusLine().getStatusCode() != HttpResponseCodes.SC_OK)) {
195  return null;
196  }
197 
198  HttpEntity entity = httpResponse.getEntity();
199  byte[] responseBytes = new byte[0];
200  if (entity != null) {
201  responseBytes = EntityUtils.toByteArray(entity);
202  }
203 
204  // Consume response content
205  if (entity != null) {
206  EntityUtils.consume(entity);
207  }
208 
209  return responseBytes;
210  }

◆ init()

void org.xdi.oxauth.service.net.HttpService.init ( )
inline
69  {
70  this.base64 = new Base64();
71  }
Base64 base64
Definition: HttpService.java:66

◆ isContentTypeXml()

boolean org.xdi.oxauth.service.net.HttpService.isContentTypeXml ( HttpResponse  httpResponse)
inline
258  {
259  Header contentType = httpResponse.getEntity().getContentType();
260  if (contentType == null) {
261  return false;
262  }
263 
264  String contentTypeValue = contentType.getValue();
265  if (StringHelper.equals(contentTypeValue, ContentType.APPLICATION_XML.getMimeType()) || StringHelper.equals(contentTypeValue, ContentType.TEXT_XML.getMimeType())) {
266  return true;
267  }
268 
269  return false;
270  }

◆ isResponseStastusCodeOk()

boolean org.xdi.oxauth.service.net.HttpService.isResponseStastusCodeOk ( HttpResponse  httpResponse)
inline
248  {
249  int responseStastusCode = httpResponse.getStatusLine().getStatusCode();
250  if (responseStastusCode == HttpStatus.SC_OK) {
251  return true;
252  }
253 
254  return false;
255  }

メンバ詳解

◆ base64

Base64 org.xdi.oxauth.service.net.HttpService.base64
private

◆ log

Logger org.xdi.oxauth.service.net.HttpService.log
private

◆ serialVersionUID

final long org.xdi.oxauth.service.net.HttpService.serialVersionUID = -2398422090669045605L
staticprivate

このクラス詳解は次のファイルから抽出されました: