/*
- * Copyright 2016 Huawei Technologies Co., Ltd.
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* HTTP Request class.</br>
*
* @author
- * @version VFC 1.0 Sep 14, 2016
+ * @version VFC 1.0 Sep 14, 2016
*/
public final class HttpRequests {
* Request builder.</br>
*
* @author
- * @version VFC 1.0 Sep 14, 2016
+ * @version VFC 1.0 Sep 14, 2016
*/
public static class Builder {
private String authenticateMode;
/**
- *
* Constructor<br>
*
* @param authenticateMode
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder(String authenticateMode) {
this.authenticateMode = authenticateMode;
* @param name
* @param value
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeader(String name, String value) {
headers.add(new Header(name, value));
* @param header
* @param headers
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeaders(Header header, Header... headers) {
if(header != null) {
*
* @param headers
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeaders(List<Header> headers) {
if(headers != null && !headers.isEmpty()) {
* @param path
* @return
* @throws VnfmException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setUrl(String url, String path) throws VnfmException {
if(StringUtils.isEmpty(url)) {
LOG.info("setUrl: url =" + url);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS,
+ new Protocol(Constant.HTTPS, SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
return this;
}
* @param defPort
* @return
* @throws VnfmException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setUrl(String url, String path, int defPort) throws VnfmException {
if(StringUtils.isEmpty(url)) {
LOG.info("setUrl: url =" + url);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), defPort));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), defPort));
return this;
}
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder post() {
this.httpMethod = new PostMethod(url);
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder get() {
this.httpMethod = new GetMethod(url);
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder put() {
this.httpMethod = new PutMethod(url);
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder delete() {
this.httpMethod = new DeleteMethod(url);
*
* @param json
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setParams(String json) {
this.paramsJson = json;
*
* @param encode
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setEncoding(String encode) {
this.encoding = encode;
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public String request() {
String result = null;
LOG.error("function=request, msg=SSLHandshake Fail, start refresh certificate ...");
SslProtocolSocketFactory socketFactory = SslProtocolSocketFactory.getInstance();
socketFactory.refresh(authenticateMode);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
LOG.error("function=request, msg=SSLHandshake Fail, certificate refresh successful .");
result = executeMethod().getResponseBodyAsString();
} catch(IOException ioe) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), ioe);
+ LOG.error(String.format("function=request, IOException msg=http request url: %s, error: ", url),
+ ioe);
} catch(VnfmException ose) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), ose);
+ LOG.error(String.format("function=request, VnfmException msg=http request url: %s, error: ", url),
+ ose);
}
} catch(IOException | VnfmException e) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), e);
+ LOG.error(String.format("function=request, IOException msg=http request url: %s, error: ", url), e);
} finally {
httpMethod.releaseConnection();
}
* @return
* @throws VnfmException
* @throws IOException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public HttpMethod execute() throws VnfmException, IOException {
try {
LOG.error("function=execute, SSLHandshake Fail, start refresh certificate ...");
SslProtocolSocketFactory socketFactory = SslProtocolSocketFactory.getInstance();
socketFactory.refresh(authenticateMode);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
LOG.error("function=execute, SSLHandshake Fail, certificate refresh successful .");
executeMethod();