List of usage examples for org.apache.http.entity BasicHttpEntity BasicHttpEntity
public BasicHttpEntity()
From source file:org.jenkinsci.plugins.skytap.ConnectToVPNTunnelStep.java
private String attachVPNToConfiguration(String confId, String networkId, String vpnId) { // build url/*from w ww . j a v a2 s.c om*/ String requestUrl = this.buildRequestURL(confId, networkId); // create request HttpPost hp = SkytapUtils.buildHttpPostRequest(requestUrl, this.authCredentials); // add content to request - vpn identifier BasicHttpEntity he = new BasicHttpEntity(); he.setContentEncoding("gzip"); he.setContentType("application/json"); // json string for vpn id String jsonString = "{\"id\":\"" + vpnId + "\"}"; InputStream stream; try { stream = new ByteArrayInputStream(jsonString.getBytes("UTF-8")); Integer len = jsonString.getBytes("UTF-8").length; long llen = len.longValue(); he.setContent(stream); he.setContentLength(llen); } catch (UnsupportedEncodingException e) { JenkinsLogger.error("Error encoding json string for vpn id: " + e.getMessage()); } hp.setEntity(he); JenkinsLogger.log("HTTP POST request: " + hp.toString()); // execute request String httpRespBody = ""; try { httpRespBody = SkytapUtils.executeHttpRequest(hp); } catch (SkytapException e) { JenkinsLogger.error("Skytap Exception: " + e.getMessage()); } // return response return httpRespBody; }
From source file:org.siddhiesb.transport.passthru.ServerWorker.java
public void run() { if (log.isDebugEnabled()) { log.debug("Starting a new Server Worker instance"); }/* w w w.j av a2 s. c o m*/ String method = request.getRequest() != null ? request.getRequest().getRequestLine().getMethod().toUpperCase() : ""; /*service dispatching logic removed... */ if ("GET".equals(method) || "DELETE".equals(method) || "OPTIONS".equals(method) || "HEAD".equals(method)) { HttpResponse response = sourceConfiguration.getResponseFactory().newHttpResponse(request.getVersion(), HttpStatus.SC_OK, request.getConnection().getContext()); // create a basic HttpEntity using the source channel of the response pipe BasicHttpEntity entity = new BasicHttpEntity(); if (request.getVersion().greaterEquals(HttpVersion.HTTP_1_1)) { entity.setChunked(true); } response.setEntity(entity); } if (request.isEntityEnclosing()) { processEntityEnclosingRequest(); } else { //processNonEntityEnclosingRESTHandler(null); } sendAck(); }
From source file:org.siddhiesb.transport.passthru.TargetResponse.java
/** * Starts the response/*from w w w .j a va 2s. c o m*/ * @param conn the client connection */ public void start(NHttpClientConnection conn) { org.siddhiesb.transport.passthru.TargetContext.updateState(conn, org.siddhiesb.transport.passthru.ProtocolState.RESPONSE_HEAD); if (expectResponseBody) { pipe = new org.siddhiesb.transport.passthru.Pipe(conn, targetConfiguration.getBufferFactory().getBuffer(), "target", targetConfiguration); org.siddhiesb.transport.passthru.TargetContext.get(conn).setReader(pipe); BasicHttpEntity entity = new BasicHttpEntity(); if (response.getStatusLine().getProtocolVersion().greaterEquals(HttpVersion.HTTP_1_1)) { entity.setChunked(true); } response.setEntity(entity); } else { if (!connStrategy.keepAlive(response, conn.getContext())) { try { // this is a connection we should not re-use org.siddhiesb.transport.passthru.TargetContext.updateState(conn, org.siddhiesb.transport.passthru.ProtocolState.CLOSING); targetConfiguration.getConnections().shutdownConnection(conn); } catch (Exception ignore) { } } else { targetConfiguration.getConnections().releaseConnection(conn); } } }
From source file:ste.web.http.HttpUtils.java
public static BasicHttpResponse getBasicResponse(final boolean withEntity) { BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, EnglishReasonPhraseCatalog.INSTANCE.getReason(HttpStatus.SC_OK, Locale.ENGLISH)); if (withEntity) { response.setEntity(new BasicHttpEntity()); }//from w ww .j av a2s . com return response; }