List of usage examples for org.apache.http.entity ContentType APPLICATION_XML
ContentType APPLICATION_XML
To view the source code for org.apache.http.entity ContentType APPLICATION_XML.
Click Source Link
From source file:org.exist.xquery.RestBinariesTest.java
private HttpResponse postXquery(final String xquery) throws JAXBException, IOException { final Query query = new Query(); query.setText(xquery);/* w ww . j a v a 2s.c om*/ final JAXBContext jaxbContext = JAXBContext.newInstance("org.exist.http.jaxb"); final Marshaller marshaller = jaxbContext.createMarshaller(); final HttpResponse response; try (final FastByteArrayOutputStream baos = new FastByteArrayOutputStream()) { marshaller.marshal(query, baos); response = executor.execute(Request.Post(getRestUrl() + "/db/").bodyByteArray(baos.toByteArray(), ContentType.APPLICATION_XML)).returnResponse(); } if (response.getStatusLine().getStatusCode() != SC_OK) { throw new IOException( "Unable to query, HTTP response code: " + response.getStatusLine().getStatusCode()); } return response; }
From source file:org.xdi.oxauth.service.net.HttpService.java
public boolean isContentTypeXml(HttpResponse httpResponse) { Header contentType = httpResponse.getEntity().getContentType(); if (contentType == null) { return false; }/*from w w w .j a v a 2s. com*/ String contentTypeValue = contentType.getValue(); if (StringHelper.equals(contentTypeValue, ContentType.APPLICATION_XML.getMimeType()) || StringHelper.equals(contentTypeValue, ContentType.TEXT_XML.getMimeType())) { return true; } return false; }
From source file:org.wuspba.ctams.ws.ITBandMemberController.java
private static void add(BandMember m) throws Exception { CTAMSDocument doc = new CTAMSDocument(); doc.getPeople().add(m.getPerson());//www . j a v a 2s . c om doc.getBandMembers().add(m); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); m.setId(doc.getBandMembers().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:com.intuit.karate.http.apache.ApacheHttpClient.java
@Override protected HttpEntity getEntity(List<MultiPartItem> items, String mediaType) { boolean hasNullName = false; for (MultiPartItem item : items) { if (item.getName() == null) { hasNullName = true;/* ww w . ja v a 2 s . com*/ break; } } if (hasNullName) { // multipart/related String boundary = createBoundary(); String text = getAsStringEntity(items, boundary); ContentType ct = ContentType.create(mediaType) .withParameters(new BasicNameValuePair("boundary", boundary)); return new StringEntity(text, ct); } else { MultipartEntityBuilder builder = MultipartEntityBuilder.create() .setContentType(ContentType.create(mediaType)); for (MultiPartItem item : items) { if (item.getValue() == null || item.getValue().isNull()) { logger.warn("ignoring null multipart value for key: {}", item.getName()); continue; } String name = item.getName(); ScriptValue sv = item.getValue(); if (name == null) { // builder.addPart(bodyPart); } else { FormBodyPartBuilder formBuilder = FormBodyPartBuilder.create().setName(name); ContentBody contentBody; switch (sv.getType()) { case INPUT_STREAM: InputStream is = (InputStream) sv.getValue(); contentBody = new InputStreamBody(is, ContentType.APPLICATION_OCTET_STREAM, name); break; case XML: contentBody = new StringBody(sv.getAsString(), ContentType.APPLICATION_XML); break; case JSON: contentBody = new StringBody(sv.getAsString(), ContentType.APPLICATION_JSON); break; default: contentBody = new StringBody(sv.getAsString(), ContentType.TEXT_PLAIN); } formBuilder = formBuilder.setBody(contentBody); builder = builder.addPart(formBuilder.build()); } } return builder.build(); } }
From source file:org.wuspba.ctams.ws.ITJudgeQualificationController.java
protected static void add() throws Exception { CTAMSDocument doc = new CTAMSDocument(); doc.getJudgeQualifications().add(TestFixture.INSTANCE.drummingQual); doc.getJudgeQualifications().add(TestFixture.INSTANCE.ensembleQual); doc.getJudgeQualifications().add(TestFixture.INSTANCE.pipingQual); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try {//from w ww . j a va2 s . c om httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); for (JudgeQualification q : doc.getJudgeQualifications()) { if (q.getPanel() == TestFixture.INSTANCE.pipingQual.getPanel() && q.getType() == TestFixture.INSTANCE.pipingQual.getType()) { TestFixture.INSTANCE.pipingQual.setId(q.getId()); } else if (q.getPanel() == TestFixture.INSTANCE.drummingQual.getPanel() && q.getType() == TestFixture.INSTANCE.drummingQual.getType()) { TestFixture.INSTANCE.drummingQual.setId(q.getId()); } else if (q.getPanel() == TestFixture.INSTANCE.ensembleQual.getPanel() && q.getType() == TestFixture.INSTANCE.ensembleQual.getType()) { TestFixture.INSTANCE.ensembleQual.setId(q.getId()); } } EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:org.wuspba.ctams.ws.ITBandRegistrationController.java
protected static void add() throws Exception { ITBandController.add();//from w w w. jav a 2 s .c om CTAMSDocument doc = new CTAMSDocument(); doc.getBands().add(TestFixture.INSTANCE.skye); doc.getBandRegistrations().add(TestFixture.INSTANCE.bandRegistration); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.bandRegistration.setId(doc.getBandRegistrations().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:org.wuspba.ctams.ws.ITSoloRegistrationController.java
private static void add() throws Exception { ITPersonController.add();//from w w w .j av a 2 s.com CTAMSDocument doc = new CTAMSDocument(); doc.getPeople().add(TestFixture.INSTANCE.elaine); doc.getSoloRegistrations().add(TestFixture.INSTANCE.soloRegistration); String xml = XMLUtils.marshal(doc); CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpPost httpPost = new HttpPost(uri); StringEntity xmlEntity = new StringEntity(xml, ContentType.APPLICATION_XML); CloseableHttpResponse response = null; try { httpPost.setEntity(xmlEntity); response = httpclient.execute(httpPost); assertEquals(IntegrationTestUtils.OK_STRING, response.getStatusLine().toString()); HttpEntity responseEntity = response.getEntity(); doc = IntegrationTestUtils.convertEntity(responseEntity); TestFixture.INSTANCE.soloRegistration.setId(doc.getSoloRegistrations().get(0).getId()); EntityUtils.consume(responseEntity); } catch (UnsupportedEncodingException ex) { LOG.error("Unsupported coding", ex); } catch (IOException ioex) { LOG.error("IOException", ioex); } finally { if (response != null) { try { response.close(); } catch (IOException ex) { LOG.error("Could not close response", ex); } } } }
From source file:org.activiti.designer.eclipse.navigator.cloudrepo.ActivitiCloudEditorUtil.java
public static JsonNode uploadNewVersion(String modelId, String filename, byte[] content, boolean firstTry) { JsonNode modelNode = null;//from w w w .ja v a2s.c om CloseableHttpClient client = getAuthenticatedClient(); try { HttpPost post = new HttpPost(PreferencesUtil.getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_URL) + "/rest/app/rest/process-models/" + modelId + "/newversion"); HttpEntity entity = MultipartEntityBuilder.create() .addBinaryBody("file", content, ContentType.APPLICATION_XML, filename).build(); post.setEntity(entity); CloseableHttpResponse response = client.execute(post); try { int statusCode = response.getStatusLine().getStatusCode(); InputStream responseContent = response.getEntity().getContent(); if (statusCode >= 200 && statusCode < 300) { modelNode = objectMapper.readTree(responseContent); } else if (statusCode == 401 && firstTry) { String cookieString = PreferencesUtil .getStringPreference(Preferences.ACTIVITI_CLOUD_EDITOR_COOKIE); if (StringUtils.isNotEmpty(cookieString)) { PreferencesUtil.getActivitiDesignerPreferenceStore() .setValue(Preferences.ACTIVITI_CLOUD_EDITOR_COOKIE.getPreferenceId(), ""); InstanceScope.INSTANCE.getNode(ActivitiPlugin.PLUGIN_ID).flush(); return uploadNewVersion(modelId, filename, content, false); } } else { JsonNode exceptionNode = null; String exceptionString = IOUtils.toString(responseContent); try { exceptionNode = objectMapper.readTree(exceptionString); } catch (Exception e) { throw new ActivitiCloudEditorException(exceptionString); } throw new ActivitiCloudEditorException(exceptionNode); } } finally { response.close(); } } catch (ActivitiCloudEditorException e) { throw e; } catch (Exception e) { Logger.logError("Error uploading new process model version", e); } finally { try { client.close(); } catch (Exception e) { } } return modelNode; }
From source file:com.osbitools.ws.shared.web.BasicWebUtils.java
public WebResponse uploadFile(String path, String fname, InputStream in, String stoken) throws ClientProtocolException, IOException { HttpPost post = new HttpPost(path); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); StringBody fn = new StringBody(fname, ContentType.MULTIPART_FORM_DATA); builder.addPart("fname", fn); builder.addBinaryBody("file", in, ContentType.APPLICATION_XML, fname); BasicCookieStore cookieStore = new BasicCookieStore(); if (stoken != null) { BasicClientCookie cookie = new BasicClientCookie(Constants.SECURE_TOKEN_NAME, stoken); cookie.setDomain(TestConstants.JETTY_HOST); cookie.setPath("/"); cookieStore.addCookie(cookie);//from w w w . j ava 2 s . c o m } TestConstants.LOG.debug("stoken=" + stoken); HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); HttpEntity entity = builder.build(); post.setEntity(entity); HttpResponse response = client.execute(post); String body; ResponseHandler<String> handler = new BasicResponseHandler(); try { body = handler.handleResponse(response); } catch (HttpResponseException e) { return new WebResponse(e.getStatusCode(), e.getMessage()); } return new WebResponse(response.getStatusLine().getStatusCode(), body); }