Example usage for org.apache.http.protocol HTTP CONTENT_TYPE

List of usage examples for org.apache.http.protocol HTTP CONTENT_TYPE

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP CONTENT_TYPE.

Prototype

String CONTENT_TYPE

To view the source code for org.apache.http.protocol HTTP CONTENT_TYPE.

Click Source Link

Usage

From source file:org.apache.synapse.util.MediatorPropertyUtils.java

/**
 * This method removes the current content-type header value from the Axis2 message context and
 * set the given value./*  ww  w .  j  a v  a2 s  .c o m*/
 * @param propertyName Message type property
 * @param resultValue Value to be set
 * @param axis2MessageCtx Axis2 message context
 */
public static void handleSpecialProperties(String propertyName, Object resultValue,
        org.apache.axis2.context.MessageContext axis2MessageCtx) {
    if (org.apache.axis2.Constants.Configuration.MESSAGE_TYPE.equals(propertyName)) {
        axis2MessageCtx.setProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE, resultValue);
        Map headers = (Map) axis2MessageCtx
                .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        if (headers != null) {
            headers.remove(HTTP.CONTENT_TYPE);
            headers.put(HTTP.CONTENT_TYPE, resultValue);
        }
    }
}

From source file:vn.vndirect.form.model.SendURIModel.java

public SendURIModel(String image, String filenameKH, String filenameKN) {
    try {//from  w w w.j  a  va  2  s .  c  o m
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost post = new HttpPost(URItoGMC + "?ImgName=" + image + "&csvKH=" + "KH" + filenameKH + ".csv"
                + "&csvKN=" + "KN" + filenameKN + ".csv");
        post.setHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=" + "UTF-16");
        //post.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse response = httpclient.execute(post);
        System.out.println("Header " + response.getFirstHeader("Location"));
    } catch (Exception e) {
    }

}

From source file:communication.Communicator.java

/**
 * Adds a new trackingPosition to an existing cartracker
 *
 * @param tracker The cartracker with a new trackingPosition
 * @return The serialnumber of the new trackingPosition
 * @throws IOException//from ww  w . j a  v  a 2s  .c  om
 */
public static Long postTrackingPositionsForTracker(CarTracker tracker) throws IOException {
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(BASE_URL_PRODUCTION + "/" + tracker.getId() + "/movements");
    String jsonBody = gson.toJson(tracker.getCurrentTrackingPeriod());
    StringEntity postingString = new StringEntity(jsonBody, CHARACTER_SET);
    post.setEntity(postingString);
    post.setHeader(HTTP.CONTENT_TYPE, "application/json");
    HttpResponse response = httpClient.execute(post);

    String responseString = EntityUtils.toString(response.getEntity(), CHARACTER_SET);
    JSONObject json = new JSONObject(responseString);
    return json.getLong("serialNumber");
}

From source file:com.baseproject.volley.toolbox.HttpHeaderParser.java

/**
 * Returns the charset specified in the Content-Type of this header,
 * or the HTTP default (ISO-8859-1) if none can be found.
 *//*  w ww  .j  a v a2s.  co  m*/
public static String parseCharset(Map<String, String> headers) {
    String result = null;
    try {
        String contentType = headers.get(HTTP.CONTENT_TYPE);
        if (contentType != null) {
            String[] params = contentType.split(";");
            for (int i = 1; i < params.length; i++) {
                String[] pair = params[i].trim().split("=");
                if (pair.length == 2) {
                    if (pair[0].equals("charset")) {
                        result = pair[1];
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        result = null;
        e.printStackTrace();
    }
    if (!TextUtils.isEmpty(result)) {
        return result;
    }
    return HTTP.UTF_8;
}

From source file:nl.nn.adapterframework.http.mime.MultipartEntity.java

MultipartEntity(MultipartForm multipart, final ContentType contentType, final long contentLength) {
    super();//from w w w. j a  va 2  s  .c  o  m
    this.multipart = multipart;
    this.contentType = new BasicHeader(HTTP.CONTENT_TYPE, contentType.toString());
    this.contentLength = contentLength;
}

From source file:com.messagemedia.restapi.client.v1.internal.http.interceptors.ContentTypeInterceptor.java

@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if ((request instanceof HttpEntityEnclosingRequest) && !request.containsHeader(HTTP.CONTENT_TYPE)) {
        request.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
    }/*from w  w w .  jav  a 2  s. c o  m*/

}

From source file:org.wso2.carbon.core.transports.util.MockTryItProcessor.java

public void process(CarbonHttpRequest request, CarbonHttpResponse response,
        ConfigurationContext configurationContext) throws Exception {
    response.addHeader(HTTP.CONTENT_TYPE, "text/html");
    PrintWriter out = response.getWriter();

    out.write("<div id=\"alertMessageBox\" style=\"display:none;position:absolute;z-index: 600;\">\n"
            + "    <!--the message area-->\n" + "    <p id=\"alertMessageBoxMessageArea\"></p>\n"
            + "    <!-- the button area-->\n" + "    <p id=\"alertButton\" align=\"right\">\n"
            + "        <input id=\"alertBoxButton\" type=\"button\"\n" + "                value=\"  OK  \"\n"
            + "                onclick=\"javascript:document.getElementById('alertMessageBox').style.display='none';return false;\"/></p>\n"
            + "</div>"
            + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/main.css\" media=\"screen, projection\" />"
            + "<script type=\"text/javascript\" src=\"../js/main.js\"></script>"
            + "<script type=\"text/javascript\">"
            + "wso2.wsf.Util.alertMessage('This function is not currently supported by WSO2 WSAS');"
            + "setTimeout(\"history.back()\",3000)" + "</script>");
    out.flush();/* ww  w. j av  a  2s . c o m*/
    out.close();
}

From source file:com.autonomy.nonaci.indexing.impl.PostDataHttpEntity.java

@Override
public Header getContentType() {
    Header header = null;//from   ww w.j  a v a  2 s . c  o  m

    final String ctString = postData.getContentType();
    if (ctString != null) {
        header = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
    }

    return header;
}

From source file:im.dadoo.logger.client.impl.DefaultLoggerClient.java

public DefaultLoggerClient(String host) {
    this.httpClient = HttpAsyncClients.createDefault();
    this.post = new HttpPost(host);
    this.post.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    this.mapper = new ObjectMapper();
}

From source file:fr.xebia.workshop.android.core.utils.ServerUtils.java

private static HttpPost buildRegistationIdRequest(String registrationId, String deviceId, Long userId)
        throws JSONException, UnsupportedEncodingException {
    HttpPost putRequest = new HttpPost(GCM_REGISTRATION_URL);
    putRequest.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    JSONObject regObject = new JSONObject();
    regObject.put("deviceId", deviceId);
    regObject.put("registrationId", registrationId);
    JSONObject userObject = new JSONObject();
    userObject.put("id", userId);
    regObject.put("user", userObject);
    putRequest.setEntity(new StringEntity(regObject.toString()));
    return putRequest;
}