List of usage examples for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity
public InputStreamRequestEntity(InputStream paramInputStream)
From source file:com.predic8.membrane.core.transport.http.ServiceInvocationTest.java
private PostMethod createPostMethod() { PostMethod post = new PostMethod("http://localhost:3016/axis2/services/BLZService?wsdl"); post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); return post;//from w w w . java 2 s .c o m }
From source file:demo.jaxrs.client.Client.java
public void addCustomerInfo(String name, String password) throws Exception { System.out.println("HTTP POST to add customer info, user : " + name + ", password : " + password); PostMethod post = new PostMethod("http://localhost:9002/customerservice/customers"); setMethodHeaders(post, name, password); RequestEntity entity = new InputStreamRequestEntity( this.getClass().getClassLoader().getResourceAsStream("add_customer.xml")); post.setRequestEntity(entity);//from w w w . j a v a2 s. c o m handleHttpMethod(post); }
From source file:eu.learnpad.core.impl.mt.XwikiBridgeInterfaceRestResource.java
@Override public InputStream transform(ModelSetType type, InputStream model) throws LpRestException { HttpClient httpClient = this.getAnonymousClient(); String uri = String.format("%s/learnpad/mt/bridge/transform", this.restPrefix); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM); postMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type.toString()); postMethod.setQueryString(queryString); RequestEntity modelEntity = new InputStreamRequestEntity(model); postMethod.setRequestEntity(modelEntity); try {/* www . j a v a2 s . co m*/ httpClient.executeMethod(postMethod); } catch (IOException e) { String message = String.format("Error in sending POST to Model Transformer component [type: %s]", type); throw new LpRestExceptionXWikiImpl(message, e); } try { return postMethod.getResponseBodyAsStream(); } catch (IOException e) { String message = String.format( "Model Transformer component failed to return result of transformation [type: %s]", type); throw new LpRestExceptionXWikiImpl(message, e); } }
From source file:eu.learnpad.core.impl.qm.XwikiBridgeInterfaceRestResource.java
@Override public void importModelSet(String modelSetId, ModelSetType type, InputStream modelContent) throws LpRestExceptionXWikiImpl { // Notify QM about a new model set imported HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/qm/bridge/importmodel/%s", DefaultRestResource.REST_URI, modelSetId);// w ww . java 2 s . c o m PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type.toString()); putMethod.setQueryString(queryString); RequestEntity requestEntity = new InputStreamRequestEntity(modelContent); putMethod.setRequestEntity(requestEntity); try { httpClient.executeMethod(putMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:eu.learnpad.core.impl.qm.XwikiCoreFacadeRestResource.java
@Override public void publish(String questionnairesId, String type, byte[] questionnairesFile) throws LpRestException { // Now actually notifying the CP via REST HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/qm/corefacade/publish/%s", DefaultRestResource.REST_URI, questionnairesId);//from ww w .jav a2 s . co m PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type); putMethod.setQueryString(queryString); InputStream stream = new ByteArrayInputStream(questionnairesFile); RequestEntity requestEntity = new InputStreamRequestEntity(stream); putMethod.setRequestEntity(requestEntity); try { httpClient.executeMethod(putMethod); } catch (IOException e) { LpRestExceptionXWikiImpl e1 = new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); throw e1; } }
From source file:com.predic8.membrane.core.transport.http.InterceptorInvocationTest.java
private PostMethod createPostMethod() { PostMethod post = new PostMethod("http://localhost:4000/axis2/services/BLZService"); post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); return post;/* ww w . j av a2 s . c o m*/ }
From source file:cz.muni.fi.pa165.creatures.rest.client.services.impl.RegionCRUDServiceImpl.java
@Override public void create(RegionDTO dto) { PostMethod postMethod = new PostMethod(uri); StringWriter writer = new StringWriter(); try {/* w ww .j av a2 s. c o m*/ context.createMarshaller().marshal(regionMapping.DTOtoEntity(dto), writer); } catch (JAXBException ex) { logger.log(Level.INFO, "Unable to marshall RegionDTO {0}", dto); return; } RequestEntity entity = new InputStreamRequestEntity(new ByteArrayInputStream(writer.toString().getBytes())); postMethod.setRequestEntity(entity); CRUDServiceHelper.send(postMethod); }
From source file:cz.muni.fi.pa165.creatures.rest.client.services.impl.WeaponCRUDServiceImpl.java
@Override public void create(WeaponDTO dto) { PostMethod postMethod = new PostMethod(uri); StringWriter writer = new StringWriter(); try {/*from w w w. j a v a 2 s. c om*/ context.createMarshaller().marshal(weaponMapping.DTOtoEntity(dto), writer); } catch (JAXBException ex) { logger.log(Level.INFO, "Unable to marshall CreatureDTO {0}", dto); return; } RequestEntity entity = new InputStreamRequestEntity(new ByteArrayInputStream(writer.toString().getBytes())); postMethod.setRequestEntity(entity); CRUDServiceHelper.send(postMethod); }
From source file:com.predic8.membrane.integration.Http10Test.java
@Test public void testMultiplePost() throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0); PostMethod post = new PostMethod("http://localhost:3000/axis2/services/BLZService"); InputStream stream = this.getClass().getResourceAsStream("/getBank.xml"); InputStreamRequestEntity entity = new InputStreamRequestEntity(stream); post.setRequestEntity(entity);/* w w w .ja va 2 s .c o m*/ post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, "\"\""); for (int i = 0; i < 100; i++) { //System.out.println("Iteration: " + i); int status = client.executeMethod(post); assertEquals(200, status); String response = post.getResponseBodyAsString(); assertNotNull(response); assertTrue(response.length() > 0); } }
From source file:com.predic8.membrane.integration.Http11Test.java
private void testPost(boolean useExpect100Continue) throws Exception { HttpClient client = new HttpClient(); if (useExpect100Continue) initExpect100ContinueWithFastFail(client); PostMethod post = new PostMethod("http://localhost:4000/axis2/services/BLZService"); InputStream stream = this.getClass().getResourceAsStream("/getBank.xml"); InputStreamRequestEntity entity = new InputStreamRequestEntity(stream); post.setRequestEntity(entity);//from www. j ava 2 s . co m post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); int status = client.executeMethod(post); // also see comment on initExpect100ContinueWithFastFail() assertEquals(200, status); assertNotNull(post.getResponseBodyAsString()); assertFalse(isNullOrEmpty(post.getResponseBodyAsString())); //System.out.println(post.getResponseBodyAsString()); }