Example usage for org.apache.commons.httpclient.methods PostMethod setRequestEntity

List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestEntity

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PostMethod setRequestEntity.

Prototype

public void setRequestEntity(RequestEntity paramRequestEntity) 

Source Link

Usage

From source file:fedora.client.FedoraClient.java

/**
 * Upload the given file to Fedora's upload interface via HTTP POST.
 *
 * @return the temporary id which can then be passed to API-M requests as a
 *         URL. It will look like uploaded://123
 *//*from  w  ww . j a v  a  2  s. com*/
public String uploadFile(File file) throws IOException {
    PostMethod post = null;
    try {
        // prepare the post method
        post = new PostMethod(getUploadURL());
        post.setDoAuthentication(true);
        post.getParams().setParameter("Connection", "Keep-Alive");

        // chunked encoding is not required by the Fedora server,
        // but makes uploading very large files possible
        post.setContentChunked(true);

        // add the file part
        Part[] parts = { new FilePart("file", file) };
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        // execute and get the response
        int responseCode = getHttpClient().executeMethod(post);
        String body = null;
        try {
            body = post.getResponseBodyAsString();
        } catch (Exception e) {
            LOG.warn("Error reading response body", e);
        }
        if (body == null) {
            body = "[empty response body]";
        }
        body = body.trim();
        if (responseCode != HttpStatus.SC_CREATED) {
            throw new IOException("Upload failed: " + HttpStatus.getStatusText(responseCode) + ": "
                    + replaceNewlines(body, " "));
        } else {
            return replaceNewlines(body, "");
        }
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}

From source file:ccc.migration.FileUploader.java

private ResourceSummary uploadFile(final String hostPath, final UUID parentId, final String fileName,
        final String originalTitle, final String originalDescription, final Date originalLastUpdate,
        final PartSource ps, final String contentType, final String charset, final boolean publish)
        throws IOException {

    final PostMethod filePost = new PostMethod(hostPath);

    try {/* w w  w. j  av a2  s . c  o m*/
        LOG.debug("Migrating file: " + fileName);
        final String name = ResourceName.escape(fileName).toString();

        final String title = (null != originalTitle) ? originalTitle : fileName;

        final String description = (null != originalDescription) ? originalDescription : "";

        final String lastUpdate;
        if (originalLastUpdate == null) {
            lastUpdate = "" + new Date().getTime();
        } else {
            lastUpdate = "" + originalLastUpdate.getTime();
        }

        final FilePart fp = new FilePart("file", ps);
        fp.setContentType(contentType);
        fp.setCharSet(charset);
        final Part[] parts = { new StringPart("fileName", name), new StringPart("title", title),
                new StringPart("description", description), new StringPart("lastUpdate", lastUpdate),
                new StringPart("path", parentId.toString()), new StringPart("publish", String.valueOf(publish)),
                fp };
        filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

        _client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_TIMEOUT);

        final int status = _client.executeMethod(filePost);
        if (status == HttpStatus.SC_OK) {
            final String entity = filePost.getResponseBodyAsString();
            LOG.debug("Upload complete, response=" + entity);

            return new S11nProvider<ResourceSummary>().readFrom(ResourceSummary.class, ResourceSummary.class,
                    null, MediaType.valueOf(filePost.getResponseHeader("Content-Type").getValue()), null,
                    filePost.getResponseBodyAsStream());
        }

        throw RestExceptionMapper.fromResponse(filePost.getResponseBodyAsString());

    } finally {
        filePost.releaseConnection();
    }
}

From source file:com.wso2telco.openidtokenbuilder.MIFEOpenIDTokenBuilder.java

/**
 * Gets the ACR app id.//from   www .  j ava2s.c  o m
 *
 * @param applicationName the application name
 * @return the ACR app id
 * @throws IdentityOAuth2Exception the identity o auth2 exception
 */
public String getACRAppID(String applicationName) throws IdentityOAuth2Exception {
    StringBuilder requestURLBuilder = new StringBuilder();
    requestURLBuilder.append(ACR_HOST_URI);
    requestURLBuilder.append("/"); //$NON-NLS-1$
    requestURLBuilder.append(APP_PROV_SERVICE);
    requestURLBuilder.append("/"); //$NON-NLS-1$
    requestURLBuilder.append(SERVICE_PROVIDER);
    String requestURL = requestURLBuilder.toString();

    JSONObject requestBody = new JSONObject();
    JSONObject createRequest = null;

    try {
        requestBody.put("appName", applicationName); //$NON-NLS-1$
        requestBody.put("serviceProviderAppId", applicationName); //$NON-NLS-1$
        requestBody.put("description", applicationName + " description"); //$NON-NLS-1$ //$NON-NLS-2$
        createRequest = new JSONObject().put("provisionAppRequest", requestBody); //$NON-NLS-1$
        StringRequestEntity requestEntity = new StringRequestEntity(createRequest.toString(),
                "application/json", "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
        PostMethod postMethod = new PostMethod(requestURL);
        postMethod.addRequestHeader("Authorization-ACR", "ServiceKey " + SERVICE_KEY); //$NON-NLS-1$ //$NON-NLS-2$
        postMethod.addRequestHeader("Authorization", "Bearer " + ACR_ACCESS_TOKEN); //$NON-NLS-1$ //$NON-NLS-2$
        postMethod.setRequestEntity(requestEntity);

        if (DEBUG) {
            log.debug("Connecting to ACR engine @ " + ACR_HOST_URI); //$NON-NLS-1$
            log.debug("Service name : " + APP_PROV_SERVICE); //$NON-NLS-1$
            log.debug("Service provider : " + SERVICE_PROVIDER); //$NON-NLS-1$
            log.debug("Request - ACR app : " + requestEntity.getContent()); //$NON-NLS-1$
        }

        httpClient = new HttpClient();
        httpClient.executeMethod(postMethod);

        String responseACRApp = new String(postMethod.getResponseBody(), "UTF-8"); //$NON-NLS-1$
        String strACR = ""; //$NON-NLS-1$
        if (null != responseACRApp && !"".equals(responseACRApp)) { //$NON-NLS-1$
            try {
                if (DEBUG) {
                    log.debug("Response - ACR app : " + responseACRApp); //$NON-NLS-1$
                }
                strACR = JsonPath.read(responseACRApp, "$.provisionAppResponse.appID"); //$NON-NLS-1$
            } catch (Exception e) {
                log.error("Provisioning of ACR app failed", e); //$NON-NLS-1$
                throw new IdentityOAuth2Exception("Provisioning of ACR app failed", e); //$NON-NLS-1$
            }
        }

        return strACR; //$NON-NLS-1$;

    } catch (UnsupportedEncodingException e) {
        log.error("Error occured while creating request", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating request", e); //$NON-NLS-1$
    } catch (JSONException e) {
        log.error("Error occured while creating request", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating request", e); //$NON-NLS-1$
    } catch (HttpException e) {
        log.error("Error occured while creating ACR app", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating ACR app", e); //$NON-NLS-1$
    } catch (IOException e) {
        log.error("Error occured while creating ACR app", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating ACR app", e); //$NON-NLS-1$
    }
}

From source file:com.adobe.share.api.ShareAPI.java

/**
 * Prepares a new HTTP multi-part POST request for uploading files. The
 * format for these requests adheres to the standard RFC1867. For details,
 * see http://www.ietf.org/rfc/rfc1867.txt.
 *
 * @param user the user//from ww w  . j av a  2  s .  c o  m
 * @param url the url
 * @param anon the anon
 * @param requestBody the request body
 * @param file the file
 *
 * @return the post method
 *
 * @throws FileNotFoundException the file not found exception
 */
protected final PostMethod createFilePostRequest(final ShareAPIUser user, final String url, final boolean anon,
        final String requestBody, final File file) throws FileNotFoundException {
    PostMethod filePost = new PostMethod(url);
    StringPart p1 = new StringPart("request", requestBody);
    Part[] parts = { p1, new FilePart("file", file.getName(), file) };
    filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

    filePost.setRequestHeader("Authorization", generateAuthorization(user, anon, "POST", url));

    return filePost;
}

From source file:com.epam.wilma.test.client.HttpRequestSender.java

/**
 * Sends a new HTTP request to a server through a proxy.
 * @param requestParameters a set of parameters that will set the content of the request
 * and specify the proxy it should go through
 *//* w ww . j a va2s  .  c  om*/
public void callWilmaTestServer(final RequestParameters requestParameters,
        final TestClientParameters clientParameters) {
    try {
        HttpClient httpClient = new HttpClient();
        String serverUrl = requestParameters.getTestServerUrl();
        logger.info("Server URL: " + serverUrl);
        PostMethod httpPost = new PostMethod(serverUrl);
        if (clientParameters.isUseProxy()) {
            String proxyHost = requestParameters.getWilmaHost();
            Integer proxyPort = requestParameters.getWilmaPort();
            logger.info("Proxy: " + proxyHost + ":" + proxyPort);
            httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
        }
        InputStream inputStream = requestParameters.getInputStream();
        if (requestParameters.getContentType().contains("fastinfoset")) {
            logger.info("Compressing it by using FIS.");
            inputStream = compress(inputStream);
        }
        if (requestParameters.getContentEncoding().contains("gzip")) {
            logger.info("Encoding it by using gzip.");
            inputStream = encode(inputStream);
            httpPost.setRequestHeader("Content-Encoding", requestParameters.getContentEncoding());
        }
        InputStreamRequestEntity entity = new InputStreamRequestEntity(inputStream,
                requestParameters.getContentType());
        httpPost.setRequestEntity(entity);
        String acceptHeader = requestParameters.getAcceptHeader();
        logger.info("Accept (header): " + acceptHeader);
        httpPost.setRequestHeader("Accept", acceptHeader);
        String acceptEncoding = requestParameters.getAcceptEncoding();
        logger.info("Accept-Encoding: " + acceptEncoding);
        httpPost.addRequestHeader("Accept-Encoding", acceptEncoding);
        logger.info("Add 'AlterMessage' header.");
        httpPost.addRequestHeader("AlterMessage", "true"); //always request alter message from Wilma
        //httpPost.addRequestHeader("0", "WilmaBypass=true");

        httpClient.getHttpConnectionManager().getParams()
                .setSendBufferSize(clientParameters.getRequestBufferSize());
        httpClient.getHttpConnectionManager().getParams()
                .setReceiveBufferSize(clientParameters.getResponseBufferSize());

        int statusCode = httpClient.executeMethod(httpPost);
        logger.info("Response Status Code: " + statusCode);
        if (clientParameters.getAllowResponseLogging()) {
            logger.info(getInputStreamAsString(httpPost.getResponseBodyAsStream()));
        }
    } catch (UnsupportedEncodingException e) {
        throw new SystemException("Unsupported encoding.", e);
    } catch (HttpException e) {
        throw new SystemException("Http exception occurred.", e);
    } catch (IOException e) {
        throw new SystemException("InputStream cannot be read.", e);
    }
}

From source file:com.wso2telco.openidtokenbuilder.MIFEOpenIDTokenBuilder.java

/**
 * Retrieve acr./* www.java 2 s .co m*/
 *
 * @param msisdn the msisdn
 * @return the string
 * @throws IdentityOAuth2Exception the identity o auth2 exception
 */
public String retrieveACR(String msisdn) throws IdentityOAuth2Exception {

    StringBuilder requestURLBuilder = new StringBuilder();
    requestURLBuilder.append(ACR_HOST_URI);
    requestURLBuilder.append("/"); //$NON-NLS-1$
    requestURLBuilder.append(RETRIEVE_SERVICE);
    requestURLBuilder.append("/"); //$NON-NLS-1$
    requestURLBuilder.append(SERVICE_PROVIDER);
    requestURLBuilder.append("/"); //$NON-NLS-1$
    requestURLBuilder.append(acrAppID);
    String requestURL = requestURLBuilder.toString();

    JSONObject requestBody = new JSONObject();
    JSONObject retrieveRequest = null;

    try {
        requestBody.put("MSISDN", msisdn); //$NON-NLS-1$
        retrieveRequest = new JSONObject().put("retriveAcrRequest", requestBody); //$NON-NLS-1$
        StringRequestEntity requestEntity = new StringRequestEntity(retrieveRequest.toString(),
                "application/json", "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
        PostMethod postMethod = new PostMethod(requestURL);
        postMethod.addRequestHeader(new Header("Authorization-ACR", "ServiceKey " + SERVICE_KEY)); //$NON-NLS-1$
        // $NON-NLS-2$
        postMethod.addRequestHeader("Authorization", "Bearer " + ACR_ACCESS_TOKEN); //$NON-NLS-1$ //$NON-NLS-2$
        postMethod.setRequestEntity(requestEntity);

        if (DEBUG) {
            log.debug("Connecting to ACR engine @ " + ACR_HOST_URI); //$NON-NLS-1$
            log.debug("Service name : " + RETRIEVE_SERVICE); //$NON-NLS-1$
            log.debug("Service provider : " + SERVICE_PROVIDER); //$NON-NLS-1$
            log.debug("App key : " + acrAppID); //$NON-NLS-1$
            log.debug("Request - retrieve ACR : " + requestEntity.getContent()); //$NON-NLS-1$
        }

        httpClient = new HttpClient();
        httpClient.executeMethod(postMethod);

        return new String(postMethod.getResponseBody(), "UTF-8"); //$NON-NLS-1$

    } catch (UnsupportedEncodingException e) {
        log.error("Error occured while creating request", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating request", e); //$NON-NLS-1$
    } catch (JSONException e) {
        log.error("Error occured while creating request", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while creating request", e); //$NON-NLS-1$
    } catch (HttpException e) {
        log.error("Error occured while retrieving ACR", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while retrieving ACR", e); //$NON-NLS-1$
    } catch (IOException e) {
        log.error("Error occured while retrieving ACR", e); //$NON-NLS-1$
        throw new IdentityOAuth2Exception("Error occured while retrieving ACR", e); //$NON-NLS-1$
    }
}

From source file:com.testmax.uri.HttpRestWithXmlBody.java

public String handleHTTPPostUnit() {

    String xmlData = "";
    String resp = "";
    // Get target URL
    String strURL = this.url;
    URLConfig urlConf = this.page.getURLConfig();

    // Prepare HTTP post
    PostMethod post = new PostMethod(strURL);

    // Request content will be retrieved directly
    // from the input stream
    // Per default, the request content needs to be buffered
    // in order to determine its length.
    // Request body buffering can be avoided when
    // content length is explicitly specified

    // Specify content type and encoding
    // If content encoding is not explicitly specified
    // ISO-8859-1 is assumed

    Set<String> s = urlConf.getUrlParamset();
    for (String param : s) {
        xmlData = urlConf.getUrlParamValue(param);
        if (param.equalsIgnoreCase("body")) {
            //xmlData=urlConf.getUrlParamValue(param);
            byte buf[] = xmlData.getBytes();
            ByteArrayInputStream in = new ByteArrayInputStream(buf);
            post.setRequestEntity(new InputStreamRequestEntity(new BufferedInputStream(in), xmlData.length()));

        } else {//from ww w  .  j  av  a  2  s  .c  om
            post.setRequestHeader(param, xmlData);
        }
        WmLog.printMessage(">>> Setting URL Param " + param + "=" + xmlData);
    }
    // Get HTTP client
    org.apache.commons.httpclient.HttpClient httpsclient = new org.apache.commons.httpclient.HttpClient();

    // Execute request
    try {

        int response = -1;
        //set the time for this HTTP request
        this.startRecording();
        long starttime = this.getCurrentTime();
        try {
            response = httpsclient.executeMethod(post);
            resp = post.getResponseBodyAsString();
            Header[] heads = post.getResponseHeaders();
            this.cookies = httpsclient.getState().getCookies();

            String header = "";
            for (Header head : heads) {
                header += head.getName() + ":" + head.getValue();
            }
            System.out.println("Header=" + header);

        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // Measure the time passed between response
        long elaspedTime = this.getElaspedTime(starttime);
        this.stopRecording(response, elaspedTime);

        System.out.println(resp);
        System.out.println("ElaspedTime: " + elaspedTime);
        WmLog.printMessage("Response XML: " + resp);
        WmLog.printMessage("ElaspedTime: " + elaspedTime);
        this.printRecording();
        this.printLog();
        if (response == 200 || response == 400) {
            this.addThreadActionMonitor(this.action, true, elaspedTime);
        } else {
            this.addThreadActionMonitor(this.action, false, elaspedTime);
            WmLog.printMessage("Input XML: " + xmlData);
            WmLog.printMessage("Response XML: " + resp);
        }
        if (resp.contains("{") && resp.contains("}") && resp.contains(":")) {
            try {
                resp = "{  \"root\": " + resp + "}";
                HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
                HierarchicalStreamDriver jsonXmlDriver = new JettisonMappedXmlDriver();
                StringWriter strWriter = new StringWriter();
                copier.copy(jsonXmlDriver.createReader(new StringReader(resp)),
                        new PrettyPrintWriter(strWriter));
                resp = strWriter.toString();
                System.out.println(resp);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    } finally {
        // Release current connection to the connection pool 
        // once you are done
        post.releaseConnection();
    }
    return resp;
}

From source file:com.apatar.http.HttpNode.java

private HttpMethod sendPost(String url, KeyInsensitiveMap data) {

    try {/*from   w w  w .  j  a v  a 2s  .  c  o m*/

        PostMethod post = new PostMethod(url);
        List<Record> recs = getTiForConnection(AbstractDataBaseNode.OUT_CONN_POINT_NAME).getSchemaTable()
                .getRecords();
        Part[] parts = new Part[recs.size() - 1];
        for (int i = 1; i < recs.size(); i++) {
            Record rec = recs.get(i);
            String fieldName = rec.getFieldName();
            Object obj = data.get(fieldName, true);
            if (obj instanceof JdbcObject) {
                obj = ((JdbcObject) obj).getValue();
            }
            if (rec.getType() == ERecordType.Binary) {
                parts[i - 1] = new FilePart(fieldName, ApplicationData.createFile("temp.temp", (byte[]) obj));
            } else {
                parts[i - 1] = new StringPart(fieldName, obj.toString());
            }
        }
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        return post;

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:fr.openwide.talendalfresco.rest.client.importer.RestImportFileTest.java

public void testSingleFileImport() {
    // create client and configure it
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);

    // instantiating a new method and configuring it
    PostMethod method = new PostMethod(restCommandUrlPrefix + "import");
    // Provide custom retry handler is necessary (?)
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    NameValuePair[] params = new NameValuePair[] { new NameValuePair("path", "/app:company_home"),
            new NameValuePair("ticket", ticket) };
    method.setQueryString(params);//from   w ww . j  av a 2  s .co m

    try {
        //method.setRequestBody(new NameValuePair[] {
        //      new NameValuePair("path", "/app:company_home") });
        FileInputStream acpXmlIs = new FileInputStream(SAMPLE_SINGLE_FILE_PATH);
        InputStreamRequestEntity entity = new InputStreamRequestEntity(acpXmlIs);
        //InputStreamRequestEntity entity = new InputStreamRequestEntity(acpXmlIs, "text/xml; charset=ISO-8859-1");
        method.setRequestEntity(entity);
    } catch (IOException ioex) {
        fail("ACP XML file not found " + ioex.getMessage());
    }

    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine());
        }

        // Read the response body.
        byte[] responseBody = method.getResponseBody();
        System.out.println(new String(responseBody)); // TODO rm

        HashSet<String> defaultElementSet = new HashSet<String>(
                Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE,
                        RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE }));
        HashMap<String, String> elementValueMap = new HashMap<String, String>(6);

        try {
            XMLEventReader xmlReader = XmlHelper.getXMLInputFactory()
                    .createXMLEventReader(new ByteArrayInputStream(responseBody));
            StringBuffer singleLevelTextBuf = null;
            while (xmlReader.hasNext()) {
                XMLEvent event = xmlReader.nextEvent();
                switch (event.getEventType()) {
                case XMLEvent.CHARACTERS:
                case XMLEvent.CDATA:
                    if (singleLevelTextBuf != null) {
                        singleLevelTextBuf.append(event.asCharacters().getData());
                    } // else element not meaningful
                    break;
                case XMLEvent.START_ELEMENT:
                    StartElement startElement = event.asStartElement();
                    String elementName = startElement.getName().getLocalPart();
                    if (defaultElementSet.contains(elementName)
                            // TODO another command specific level
                            || "ticket".equals(elementName)) {
                        // reinit buffer at start of meaningful elements
                        singleLevelTextBuf = new StringBuffer();
                    } else {
                        singleLevelTextBuf = null; // not useful
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    if (singleLevelTextBuf == null) {
                        break; // element not meaningful
                    }

                    // TODO or merely put it in the map since the element has been tested at start
                    EndElement endElement = event.asEndElement();
                    elementName = endElement.getName().getLocalPart();
                    if (defaultElementSet.contains(elementName)) {
                        String value = singleLevelTextBuf.toString();
                        elementValueMap.put(elementName, value);
                        // TODO test if it is code and it is not OK, break to error handling
                    }
                    // TODO another command specific level
                    else if ("ticket".equals(elementName)) {
                        ticket = singleLevelTextBuf.toString();
                    }
                    // singleLevelTextBuf = new StringBuffer(); // no ! in start
                    break;
                }
            }
        } catch (XMLStreamException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Throwable t) {
            // TODO Auto-generated catch block
            t.printStackTrace();
            //throw t;
        }

        String code = elementValueMap.get(RestConstants.TAG_CODE);
        assertTrue(RestConstants.CODE_OK.equals(code));
        System.out.println("got ticket " + ticket);

    } catch (HttpException e) {
        // TODO
        e.printStackTrace();
    } catch (IOException e) {
        // TODO
        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:com.ikanow.infinit.e.harvest.enrichment.legacy.opencalais.ExtractorOpenCalais.java

private PostMethod createPostMethod(String text) throws UnsupportedEncodingException {

    if (text.length() > MAX_LENGTH) {
        text = text.substring(0, MAX_LENGTH);
    }//from   www  .  j a  v  a  2s  . com
    PostMethod method = new PostMethod(CALAIS_URL);

    // Set mandatory parameters
    method.setRequestHeader("x-calais-licenseID", CALAIS_LICENSE.trim());

    // Set input content type
    method.setRequestHeader("Content-Type", "text/raw; charset=UTF-8");

    // Set response/output format
    method.setRequestHeader("Accept", "application/json");

    method.setRequestHeader("enableMetadataType", "GenericRelations");
    // Enable Social Tags processing
    method.setRequestEntity(new StringRequestEntity(text, "text/plain", "UTF-8"));
    return method;
}