List of usage examples for org.apache.http.entity ContentType APPLICATION_JSON
ContentType APPLICATION_JSON
To view the source code for org.apache.http.entity ContentType APPLICATION_JSON.
Click Source Link
From source file:org.apache.james.jmap.HttpJmapAuthentication.java
public static AccessToken authenticateJamesUser(URIBuilder uriBuilder, String username, String password) throws ClientProtocolException, IOException, URISyntaxException { String continuationToken = getContinuationToken(uriBuilder, username); Response response = Request.Post(uriBuilder.setPath("/authentication").build()) .bodyString("{\"token\": \"" + continuationToken + "\", \"method\": \"password\", \"password\": \"" + password + "\"}", ContentType.APPLICATION_JSON) .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute(); return AccessToken.fromString(JsonPath.parse(response.returnContent().asString()).read("accessToken")); }
From source file:org.kitodo.data.elasticsearch.index.type.TemplateType.java
@SuppressWarnings("unchecked") @Override/*from ww w.j a v a2s . c o m*/ public HttpEntity createDocument(Template template) { JSONObject templateObject = new JSONObject(); templateObject.put("origin", template.getOrigin()); Integer process = template.getProcess() != null ? template.getProcess().getId() : null; templateObject.put("process", process); templateObject.put("properties", addObjectRelation(template.getProperties())); return new NStringEntity(templateObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.index.elasticsearch.type.RulesetType.java
@SuppressWarnings("unchecked") @Override/* w ww. j a va 2s.c om*/ public HttpEntity createDocument(Ruleset ruleset) { LinkedHashMap<String, String> orderedRulesetMap = new LinkedHashMap<>(); orderedRulesetMap.put("title", ruleset.getTitle()); orderedRulesetMap.put("file", ruleset.getFile()); orderedRulesetMap.put("fileContent", ""); JSONObject rulesetObject = new JSONObject(orderedRulesetMap); return new NStringEntity(rulesetObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.sentilo.common.rest.hmac.HMACBuilder.java
public static String buildHeader(final String body, final String endpoint, final String secret, final String currentDate) throws GeneralSecurityException { final String contentMd5 = calculateMD5(body); final String toSign = getContentToSign(HTTP_VERB, contentMd5, ContentType.APPLICATION_JSON.getMimeType(), currentDate, endpoint);//from w ww . ja va 2 s .co m return calculateHMAC(secret, toSign); }
From source file:com.msopentech.odatajclient.engine.format.ODataFormat.java
/** * Gets OData format from its string representation. * * @param format string representation of the format. * @return OData format./*from w w w. j av a2 s . c o m*/ */ public static ODataFormat fromString(final String format) { ODataFormat result = null; final StringBuffer _format = new StringBuffer(); final String[] parts = format.split(";"); _format.append(parts[0]); if (ContentType.APPLICATION_JSON.getMimeType().equals(parts[0])) { if (parts.length > 1) { _format.append(';').append(parts[1]); } else { result = ODataFormat.JSON; } } if (result == null) { final String candidate = _format.toString().replaceAll(" ", ""); for (ODataFormat value : values()) { if (candidate.equals(value.toString())) { result = value; } } } if (result == null) { throw new IllegalArgumentException("Unsupported format: " + format); } return result; }
From source file:com.msopentech.odatajclient.engine.format.ODataPubFormat.java
/** * Gets OData format from its string representation. * * @param format string representation of the format. * @return OData format.//from ww w . j ava 2s . c o m */ public static ODataPubFormat fromString(final String format) { ODataPubFormat result = null; final StringBuffer _format = new StringBuffer(); final String[] parts = format.split(";"); _format.append(parts[0]); if (ContentType.APPLICATION_JSON.getMimeType().equals(parts[0])) { if (parts.length > 1 && parts[1].startsWith("odata=")) { _format.append(';').append(parts[1]); } else { result = ODataPubFormat.JSON; } } if (result == null) { final String candidate = _format.toString(); for (ODataPubFormat value : values()) { if (candidate.equals(value.toString())) { result = value; } } } if (result == null) { throw new IllegalArgumentException("Unsupported format: " + format); } return result; }
From source file:com.ibm.watson.app.common.util.rest.JSONEntity.java
public JSONEntity(String json) throws UnsupportedEncodingException { super(json, ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.elasticsearch.index.type.HistoryType.java
@SuppressWarnings("unchecked") @Override/*from w w w . j ava 2 s . c om*/ public HttpEntity createDocument(History history) { JSONObject historyObject = new JSONObject(); historyObject.put("numericValue", history.getNumericValue()); historyObject.put("stringValue", history.getStringValue()); historyObject.put("type", history.getHistoryType().getValue()); String date = history.getDate() != null ? formatDate(history.getDate()) : null; historyObject.put("date", date); Integer process = history.getProcess() != null ? history.getProcess().getId() : null; historyObject.put("process", process); return new NStringEntity(historyObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:de.pubflow.server.core.restConnection.WorkflowSender.java
/** * Sends a post request to the Workflow engine to use a certain Workflow * specified through the given path./*from w w w . jav a 2 s.c o m*/ * * @param wfCall * The message with all necessary informations to create a new * Workflow * @param workflowPath * The path for the specific Workflow to be used. * @throws WFRestException * if the connection responses with a HTTP response code other * than 2xx */ public static void initWorkflow(WorkflowRestCall wfCall, String workflowPath) throws WFRestException { Logger myLogger = LoggerFactory.getLogger(WorkflowSender.class); myLogger.info("Trying to use workflow on: " + workflowPath); Gson gson = new Gson(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(workflowPath); HttpResponse response = null; try { StringEntity postingString = new StringEntity(gson.toJson(wfCall), ContentType.APPLICATION_JSON); post.setEntity(postingString); post.setHeader("Content-type", "application/json;charset=utf-8"); response = httpClient.execute(post); System.out.println(post.getURI()); myLogger.info("Http response: " + response.toString()); } catch (Exception e) { myLogger.error("Could not deploy new Workflow with ID: " + wfCall.getID()); myLogger.error(e.toString()); throw new WFRestException("Workflow could not be started"); } if (response.getStatusLine().getStatusCode() >= 300) { throw new WFRestException( "The called WorkflowService send status code: " + response.getStatusLine().getStatusCode() + " and error: " + response.getStatusLine().getReasonPhrase()); } }
From source file:com.vmware.photon.controller.clustermanager.clients.HttpClientTestUtil.java
@SuppressWarnings("unchecked") public static CloseableHttpAsyncClient setupMocks(String serializedResponse, int responseCode) throws IOException { CloseableHttpAsyncClient asyncHttpClient = Mockito.mock(CloseableHttpAsyncClient.class); Mockito.doAnswer(new Answer<Object>() { @Override/* w w w. j a v a 2 s . co m*/ public Object answer(InvocationOnMock invocation) throws Throwable { return null; } }).when(asyncHttpClient).close(); final HttpResponse httpResponse = Mockito.mock(HttpResponse.class); StatusLine statusLine = Mockito.mock(StatusLine.class); Mockito.when(httpResponse.getStatusLine()).thenReturn(statusLine); Mockito.when(statusLine.getStatusCode()).thenReturn(responseCode); Mockito.when(httpResponse.getEntity()) .thenReturn(new StringEntity(serializedResponse, ContentType.APPLICATION_JSON)); final Future<HttpResponse> httpResponseFuture = new Future<HttpResponse>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public HttpResponse get() throws InterruptedException, ExecutionException { return httpResponse; } @Override public HttpResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return httpResponse; } }; Mockito.when( asyncHttpClient.execute(Matchers.any(HttpUriRequest.class), Matchers.any(BasicHttpContext.class), Matchers.any(org.apache.http.concurrent.FutureCallback.class))) .thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocation.getArguments()[2] != null) { ((org.apache.http.concurrent.FutureCallback<HttpResponse>) invocation.getArguments()[2]) .completed(httpResponse); } return httpResponseFuture; } }); return asyncHttpClient; }