use of org.apache.http.entity.mime.content.StringBody in project perun by CESNET.
the class MUStrategy method getHttpRequest.
@Override
public HttpUriRequest getHttpRequest(String uco, int yearSince, int yearTill, PublicationSystem ps) {
// prepare request body
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
try {
entityBuilder.addPart("typ", new StringBody("xml", ContentType.create("text/plain", Consts.UTF_8)));
entityBuilder.addPart("kodovani", new StringBody(StandardCharsets.UTF_8.toString(), ContentType.create("text/plain", Consts.UTF_8)));
entityBuilder.addPart("keyfile", new ByteArrayBody(buildRequestKeyfile(Integer.parseInt(uco), yearSince, yearTill).getBytes(), "template.xml"));
} catch (Exception e) {
throw new RuntimeException(e);
}
// prepare post request
HttpPost post = new HttpPost(ps.getUrl());
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(ps.getUsername(), ps.getPassword());
// cred, enc, proxy
post.addHeader(BasicScheme.authenticate(credentials, StandardCharsets.UTF_8.toString(), false));
post.setEntity(entityBuilder.build());
return post;
}
use of org.apache.http.entity.mime.content.StringBody in project streamsx.topology by IBMStreams.
the class StreamingAnalyticsServiceV2 method submitBuildArtifact.
/**
* Submit the job from the built artifact.
*/
@Override
protected JsonObject submitBuildArtifact(CloseableHttpClient httpclient, JsonObject jobConfigOverlays, String submitUrl) throws IOException {
HttpPost postArtifact = new HttpPost(submitUrl);
postArtifact.addHeader("Authorization", getAuthorization());
StringBody paramsBody = new StringBody(jobConfigOverlays.toString(), ContentType.APPLICATION_JSON);
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("job_options", paramsBody).build();
postArtifact.setEntity(reqEntity);
JsonObject jso = StreamsRestUtils.getGsonResponse(httpclient, postArtifact);
TRACE.info("Streaming Analytics service (" + getName() + "): submit job response: " + jso.toString());
return jso;
}
use of org.apache.http.entity.mime.content.StringBody in project jackrabbit by apache.
the class Utils method addPart.
/**
* @param paramName
* @param value
* @param resolver
* @throws RepositoryException
*/
static void addPart(String paramName, QValue value, NamePathResolver resolver, List<FormBodyPart> parts, List<QValue> binaries) throws RepositoryException {
FormBodyPartBuilder builder = FormBodyPartBuilder.create().setName(paramName);
ContentType ctype = ContentType.create(JcrValueType.contentTypeFromType(value.getType()), DEFAULT_CHARSET);
FormBodyPart part;
switch(value.getType()) {
case PropertyType.BINARY:
binaries.add(value);
// server detects binaries based on presence of filename parameters (JCR-4154)
part = builder.setBody(new InputStreamBody(value.getStream(), ctype, paramName)).build();
break;
case PropertyType.NAME:
part = builder.setBody(new StringBody(resolver.getJCRName(value.getName()), ctype)).build();
break;
case PropertyType.PATH:
part = builder.setBody(new StringBody(resolver.getJCRPath(value.getPath()), ctype)).build();
break;
default:
part = builder.setBody(new StringBody(value.getString(), ctype)).build();
}
parts.add(part);
}
use of org.apache.http.entity.mime.content.StringBody in project undertow by undertow-io.
the class MultiPartTestCase method testMultiPartIndividualFileToLarge.
@Test
public void testMultiPartIndividualFileToLarge() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/3";
HttpPost post = new HttpPost(uri);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
entity.addPart("file", new FileBody(new File(MultiPartTestCase.class.getResource("uploadfile.txt").getFile())));
post.setEntity(entity);
HttpResponse result = client.execute(post);
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("EXCEPTION: class java.lang.IllegalStateException", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.entity.mime.content.StringBody in project undertow by undertow-io.
the class MultiPartTestCase method testMultiPartRequestUtf8CharsetInPart.
@Test
public void testMultiPartRequestUtf8CharsetInPart() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/1";
HttpPost post = new HttpPost(uri);
MultipartEntity entity = new MultipartEntity();
entity.addPart("formValue", new StringBody("myValue\u00E5", ContentType.create("text/plain", StandardCharsets.UTF_8)));
post.setEntity(entity);
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("PARAMS:\r\n" + "parameter count: 1\r\n" + "parameter name count: 1\r\n" + "name: formValue\r\n" + "filename: null\r\n" + "content-type: text/plain; charset=UTF-8\r\n" + "Content-Disposition: form-data; name=\"formValue\"\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n" + "size: 9\r\n" + "content: myValue\u00E5\r\n", response);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations