Java Code Examples for java.net.HttpURLConnection#getRequestMethod()

The following examples show how to use java.net.HttpURLConnection#getRequestMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelfThrottlingIntercept.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void responseReceived(ResponseReceivedEvent event) {
  RequestResult result = event.getRequestResult();
  Date startDate = result.getStartDate();
  Date stopDate = result.getStopDate();
  long elapsed = stopDate.getTime() - startDate.getTime();

  synchronized (this) {
    this.lastE2Elatency = elapsed;
  }

  if (LOG.isDebugEnabled()) {
    int statusCode = result.getStatusCode();
    String etag = result.getEtag();
    HttpURLConnection urlConnection = (HttpURLConnection) event
        .getConnectionObject();
    int contentLength = urlConnection.getContentLength();
    String requestMethod = urlConnection.getRequestMethod();
    long threadId = Thread.currentThread().getId();
    LOG.debug(String
        .format(
            "SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s",
            threadId, statusCode, elapsed, etag, contentLength, requestMethod));
  }
}
 
Example 2
Source File: CiviRestService.java    From civicrm-data-integration with GNU General Public License v3.0 6 votes vote down vote up
public Long getRowCount(String params) throws IOException, CiviCRMException, ParseException {
    if (!this.isFirst && (this.action.equals("getoptions") || this.action.equals("getvalue") || this.action.equals("getsingle"))) {
        return 0L;
    } else if (this.isFirst) {
        if (this.action.equals("getoptions") || this.action.equals("getvalue") || this.action.equals("getsingle")) {
            return 1L;
        } else {
            URL url = getUrl(entity, "getcount", params);
            HttpURLConnection conn = getHttpConnection("GET", url);
            this.callUrl = conn.getRequestMethod() + ": " + url.toString();

            String jsonResponse = getCiviResponse(conn);
            JSONObject jsonObject = (JSONObject) parser.parse(jsonResponse);

            // Aqui debo chequear si hay un error de acceso
            if ((Long) jsonObject.get("is_error") == 1L) {
                throw new CiviCRMException("CiviCRM API Error: " + jsonObject.get("error_message").toString());
            } else {
                this.entityCount = Long.valueOf(jsonObject.get("result").toString());
            }
        }
    }
    return this.entityCount;
}
 
Example 3
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 4
Source File: HttpResponseCache.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 5
Source File: HttpResponseCache.java    From wildfly-samples with MIT License 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 6
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 7
Source File: HttpResponseCache.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 8
Source File: HttpResponseCache.java    From reader with MIT License 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 9
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 10
Source File: SelfThrottlingIntercept.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void responseReceived(ResponseReceivedEvent event) {
  RequestResult result = event.getRequestResult();
  Date startDate = result.getStartDate();
  Date stopDate = result.getStopDate();
  long elapsed = stopDate.getTime() - startDate.getTime();

  synchronized (this) {
    this.lastE2Elatency = elapsed;
  }

  if (LOG.isDebugEnabled()) {
    int statusCode = result.getStatusCode();
    String etag = result.getEtag();
    HttpURLConnection urlConnection = (HttpURLConnection) event
        .getConnectionObject();
    int contentLength = urlConnection.getContentLength();
    String requestMethod = urlConnection.getRequestMethod();
    long threadId = Thread.currentThread().getId();
    LOG.debug(String
        .format(
            "SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s",
            threadId, statusCode, elapsed, etag, contentLength, requestMethod));
  }
}
 
Example 11
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  if (isHttps()) {
    HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
    cipherSuite = httpsConnection.getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = httpsConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = httpsConnection.getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
Example 12
Source File: URLConnectionInspectorRequest.java    From stetho with MIT License 5 votes vote down vote up
public URLConnectionInspectorRequest(
    String requestId,
    String friendlyName,
    HttpURLConnection configuredRequest,
    @Nullable SimpleRequestEntity requestEntity,
    RequestBodyHelper requestBodyHelper) {
  super(Util.convertHeaders(configuredRequest.getRequestProperties()));
  mRequestId = requestId;
  mFriendlyName = friendlyName;
  mRequestEntity = requestEntity;
  mRequestBodyHelper = requestBodyHelper;
  mUrl = configuredRequest.getURL().toString();
  mMethod = configuredRequest.getRequestMethod();
}
 
Example 13
Source File: HttpsUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 得到响应对象
 * @param urlConnection
 * @param content 网页内容
 * @return 响应对象
 * @throws IOException
 */ 
private HttpResponse makeContent(String urlString, HttpURLConnection urlConnection, String content) throws IOException { 
    HttpResponse httpResponser = new HttpResponse(); 
    try { 
        httpResponser.contentCollection = new Vector<String>(); 
        String ecod = urlConnection.getContentEncoding(); 
        if (ecod == null) 
            ecod = this.encode; 
        httpResponser.urlString = urlString; 
        this.cookies=urlConnection.getHeaderField("Set-Cookie");
        httpResponser.cookie=this.cookies;
        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort(); 
        httpResponser.file = urlConnection.getURL().getFile(); 
        httpResponser.host = urlConnection.getURL().getHost(); 
        httpResponser.path = urlConnection.getURL().getPath(); 
        httpResponser.port = urlConnection.getURL().getPort(); 
        httpResponser.protocol = urlConnection.getURL().getProtocol(); 
        httpResponser.query = urlConnection.getURL().getQuery(); 
        httpResponser.ref = urlConnection.getURL().getRef(); 
        httpResponser.userInfo = urlConnection.getURL().getUserInfo(); 
        httpResponser.content = content;
        httpResponser.contentEncoding = ecod; 
        httpResponser.code = urlConnection.getResponseCode(); 
        httpResponser.message = urlConnection.getResponseMessage(); 
        httpResponser.contentType = urlConnection.getContentType(); 
        httpResponser.method = urlConnection.getRequestMethod(); 
        httpResponser.connectTimeout = urlConnection.getConnectTimeout(); 
        httpResponser.readTimeout = urlConnection.getReadTimeout(); 
        httpResponser.headerFields = urlConnection.getHeaderFields();
        return httpResponser; 
    } catch (IOException e) { 
        throw e; 
    } finally { 
        if (urlConnection != null) 
            urlConnection.disconnect(); 
    } 
}
 
Example 14
Source File: HttpURLConnectionAspect.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private static @Nullable TraceEntryOrTimer onBefore(ThreadContext threadContext,
        HttpURLConnection httpURLConnection, boolean overrideGetWithPost) {
    if (!(httpURLConnection instanceof HasTraceEntryMixin)) {
        return null;
    }
    TraceEntry traceEntry =
            ((HasTraceEntryMixin) httpURLConnection).glowroot$getTraceEntry();
    if (traceEntry != null) {
        return new TraceEntryOrTimer(traceEntry.extend());
    }
    String method = httpURLConnection.getRequestMethod();
    if (method == null) {
        method = "";
    } else if (overrideGetWithPost && method.equals("GET")) {
        // this is to match behavior in
        // sun.net.www.protocol.http.HttpURLConnection.getOutputStream0()
        method = "POST ";
    } else {
        method += " ";
    }
    URL urlObj = httpURLConnection.getURL();
    String url;
    if (urlObj == null) {
        url = "";
    } else {
        url = urlObj.toString();
    }
    traceEntry = threadContext.startServiceCallEntry("HTTP",
            method + Uris.stripQueryString(url),
            MessageSupplier.create("http client request: {}{}", method, url), timerName);
    ((HasTraceEntryMixin) httpURLConnection).glowroot$setTraceEntry(traceEntry);
    return new TraceEntryOrTimer(traceEntry);
}
 
Example 15
Source File: HttpResponseCache.java    From reader with MIT License 4 votes vote down vote up
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();

  if (maybeRemove(requestMethod, uri)) {
    return null;
  }
  if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(uriToKey(uri));
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
Example 16
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 4 votes vote down vote up
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();

  if (maybeRemove(requestMethod, uri)) {
    return null;
  }
  if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(uriToKey(uri));
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
Example 17
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 4 votes vote down vote up
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();

  if (maybeRemove(requestMethod, uri)) {
    return null;
  }
  if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(uriToKey(uri));
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
Example 18
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 4 votes vote down vote up
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();
  String key = uriToKey(uri);

  if (requestMethod.equals("POST") || requestMethod.equals("PUT") || requestMethod.equals(
      "DELETE")) {
    try {
      cache.remove(key);
    } catch (IOException ignored) {
      // The cache cannot be written.
    }
    return null;
  } else if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(key);
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
Example 19
Source File: HttpUtil.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 得到响应对象
 * @param urlConnection
 * @return 响应对象
 * @throws IOException
 */ 
private HttpResponse makeContent(String urlString, HttpURLConnection urlConnection) throws IOException { 
	urlConnection.setConnectTimeout(this.timeout);
	urlConnection.setReadTimeout(this.timeout);
    HttpResponse httpResponser = new HttpResponse(); 
    try { 
        InputStream in = urlConnection.getInputStream(); 
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); 
        httpResponser.contentCollection = new Vector<String>(); 
        StringBuffer temp = new StringBuffer(); 
        String line = bufferedReader.readLine(); 
        while (line != null) { 
            httpResponser.contentCollection.add(line); 
            temp.append(line).append("\r\n"); 
            line = bufferedReader.readLine(); 
        } 
        bufferedReader.close(); 
        String ecod = urlConnection.getContentEncoding(); 
        if (ecod == null) 
            ecod = this.encode; 
        httpResponser.urlString = urlString; 
        //urlConnection.getHeaderField("Set-Cookie");获取到的COOKIES不全,会将JSESSIONID漏掉,故而采用此中方式
        if(this.cookies == null || this.cookies.equals("")){
        	if(urlConnection.getHeaderFields().get("Set-Cookie") != null){
        		List<String> listS = urlConnection.getHeaderFields().get("Set-Cookie");
        		String cookie = "";
            	if(listS != null){
                    for (int i = 0; i < listS.size(); i++) {
        				cookie = cookie + (cookie.equals("")? "":", ") + listS.get(i);
        			}
            	}else{
            		cookie = urlConnection.getHeaderField("Set-Cookie");
            	}
            	this.cookies=cookie;
            	httpResponser.cookie=this.cookies;
        	}
        }
        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort(); 
        httpResponser.file = urlConnection.getURL().getFile(); 
        httpResponser.host = urlConnection.getURL().getHost(); 
        httpResponser.path = urlConnection.getURL().getPath(); 
        httpResponser.port = urlConnection.getURL().getPort(); 
        httpResponser.protocol = urlConnection.getURL().getProtocol(); 
        httpResponser.query = urlConnection.getURL().getQuery(); 
        httpResponser.ref = urlConnection.getURL().getRef(); 
        httpResponser.userInfo = urlConnection.getURL().getUserInfo(); 
        httpResponser.content = new String(temp.toString().getBytes(), ecod); 
        httpResponser.contentEncoding = ecod; 
        httpResponser.code = urlConnection.getResponseCode(); 
        httpResponser.message = urlConnection.getResponseMessage(); 
        httpResponser.contentType = urlConnection.getContentType(); 
        httpResponser.method = urlConnection.getRequestMethod(); 
        httpResponser.connectTimeout = urlConnection.getConnectTimeout(); 
        httpResponser.readTimeout = urlConnection.getReadTimeout(); 
        httpResponser.headerFields = urlConnection.getHeaderFields();
    } catch (IOException e) { 
    	httpResponser.code = 404;
    } finally { 
        if (urlConnection != null) 
            urlConnection.disconnect(); 
    } 
    return httpResponser; 
}
 
Example 20
Source File: MbgaOauthUtil.java    From gameserver with Apache License 2.0 3 votes vote down vote up
/**
 * set header for auth.
 * 
 * @param req
 *          http request
 * @param uri
 *          uri without param
 * @param urlParam
 *          url's param. split by '&'
 * @param consumer
 *          consumer
 * @param token
 *          token
 * @param verifier
 *          verifier
 */
public static void setAuthHeader(
/* HttpRequestBase req, */HttpURLConnection conn, String uri,
		String urlParam, Consumer consumer, Token token, String verifier) {
	String method = conn.getRequestMethod();// req.getMethod();
	TreeMap<String, String> paramMapForSign = generateMapByParam(urlParam);
	String headerValue = createAuthHeaderForResource(method, uri,
			paramMapForSign, consumer, token, verifier);
	// req.setHeader("Authorization", headerValue);
	// req.setHeader("Content-Type", "application/json; charset=utf8");
	conn.setRequestProperty("Authorization", headerValue);
	conn.setRequestProperty("Content-Type", "application/json; charset=utf8");
	// conn.setRequestProperty("Content-Length","0");
}