List of usage examples for org.apache.commons.httpclient.methods FileRequestEntity FileRequestEntity
public FileRequestEntity(final File file, final String contentType)
From source file:org.sakaiproject.entitybroker.util.http.HttpRESTUtils.java
protected static void handleRequestData(EntityEnclosingMethod method, Object data) { if (method == null) { throw new IllegalArgumentException("Invalid method, cannot be null"); }/*from w w w .ja v a 2s . co m*/ if (data != null) { RequestEntity re = null; if (data.getClass().isAssignableFrom(InputStream.class)) { re = new InputStreamRequestEntity((InputStream) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(byte[].class)) { re = new ByteArrayRequestEntity((byte[]) data, CONTENT_TYPE_UTF8); } else if (data.getClass().isAssignableFrom(File.class)) { re = new FileRequestEntity((File) data, CONTENT_TYPE_UTF8); } else { // handle as a string try { re = new StringRequestEntity(data.toString(), "text/xml", ENCODING_UTF8); } catch (UnsupportedEncodingException e) { throw new HttpIOException("Encoding data using UTF8 failed :: " + e.getMessage(), e); } } method.setRequestEntity(re); } }
From source file:org.sonatype.nexus.integrationtests.nexus4548.Nexus4548RepoTargetPermissionMatchesPathInRepoIT.java
private HttpMethod put(final String gavPath, final int code) throws Exception { PutMethod putMethod = new PutMethod(getNexusTestRepoUrl() + gavPath); putMethod.setRequestEntity(new FileRequestEntity(getTestFile("pom-a.pom"), "text/xml")); final HttpMethod httpMethod = RequestFacade.executeHTTPClientMethod(putMethod); assertThat(httpMethod.getStatusCode(), Matchers.is(code)); return httpMethod; }
From source file:org.switchyard.component.test.mixins.http.HTTPMixIn.java
/** * POST the specified request payload to the specified HTTP endpoint. * @param endpointURL The HTTP endpoint URL. * @param request The file resource containing the request payload. * @return The HTTP response payload./*from ww w. jav a2 s .c om*/ */ public String postFile(String endpointURL, String request) { FileRequestEntity requestEntity = new FileRequestEntity(new File(request), "text/xml; charset=utf-8"); if (_dumpMessages) { _logger.info("Sending a POST request to [" + endpointURL + "]"); ByteArrayOutputStream target = new ByteArrayOutputStream(); try { requestEntity.writeRequest(target); _logger.info("Request body:[" + target.toString() + "]"); } catch (IOException e) { _logger.error("Unable to write FileRequestEntity to stream", e); } } PostMethod postMethod = new PostMethod(endpointURL); postMethod.setRequestEntity(requestEntity); try { return execute(postMethod); } finally { postMethod.releaseConnection(); } }
From source file:org.wso2.carbon.esb.mediator.test.property.PropertyIntegrationForceSCAcceptedPropertyTestCase.java
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " + "- Enabled False") public void testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario() throws Exception { loadESBConfigurationFromClasspath("/artifacts/ESB/mediatorconfig/property/FORCE_SC_ACCEPTED_Disabled.xml"); int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "GetQuoteRequest.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("Axis2ProxyService")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity);//from ww w .j av a2s . c o m post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 200, "Response status should be 200"); }
From source file:org.wso2.carbon.esb.mediator.test.property.PropertyIntegrationForceSCAcceptedPropertyTestCase.java
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " + "Enabled True - " + "Client should receive 202 message", dependsOnMethods = "testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario") public void testWithFORCE_SC_ACCEPTEDPropertyEnabledTrueScenario() throws Exception { loadESBConfigurationFromClasspath("/artifacts/ESB/mediatorconfig/property/FORCE_SC_ACCEPTED_Enabled.xml"); int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "PlaceOrder.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("Axis2ProxyOutOnlyService")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity);//from www . j av a 2 s . c o m post.setRequestHeader("SOAPAction", "placeOrder"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 202, "Response status should be 202"); }
From source file:org.wso2.carbon.esb.mediator.test.property.PropertyIntegrationHTTP_SCTestCase.java
@Test(groups = "wso2.esb", description = "Getting HTTP status code number ") public void testEnrichMediator() throws Exception { int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "GetQuoteRequest.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("Axis2ProxyService")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity);/*from w w w. ja v a2s . c o m*/ post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 404, "Response status should be 404"); }
From source file:org.wso2.carbon.esb.mediators.callout.ESBJAVA_4118_SOAPHeaderHandlingTest.java
@Test(groups = "wso2.esb", description = "Test whether the callout mediator successfully handle SOAP messages " + "Having SOAP header") public void testSOAPHeaderHandling() throws Exception { String endpoint = "http://localhost:8480/services/TestCallout"; String soapRequest = TestConfigurationProvider.getResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "callout" + File.separator + "SOAPRequestWithHeader.xml"; File input = new File(soapRequest); PostMethod post = new PostMethod(endpoint); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity);/*from w w w .ja v a 2 s.co m*/ post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpClient = new HttpClient(); boolean errorLog = false; try { int result = httpClient.executeMethod(post); String responseBody = post.getResponseBodyAsString(); log.info("Response Status: " + result); log.info("Response Body: " + responseBody); LogEvent[] logs = logViewerClient.getAllSystemLogs(); for (LogEvent logEvent : logs) { if (logEvent.getPriority().equals("ERROR")) { String message = logEvent.getMessage(); if (message.contains("Unable to convert to SoapHeader Block")) { errorLog = true; break; } } } } finally { post.releaseConnection(); } assertFalse(errorLog, "Mediator Hasn't invoked successfully."); }
From source file:org.wso2.carbon.esb.mediators.callout.ESBJAVA_4239_HTTP_SC_HandlingTests.java
@Test(groups = "wso2.esb", description = "Test whether response HTTP status code getting correctly after callout " + "mediator successfully execute") public void testHttpStatusCodeGettingSuccessfully() throws Exception { String endpoint = getProxyServiceURLHttp("TestCallout"); String soapRequest = TestConfigurationProvider.getResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "callout" + File.separator + "SOAPRequestWithHeader.xml"; File input = new File(soapRequest); PostMethod post = new PostMethod(endpoint); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity);/*from ww w . j ava 2 s . c o m*/ post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpClient = new HttpClient(); boolean errorLog = false; try { httpClient.executeMethod(post); LogEvent[] logs = logViewerClient.getAllSystemLogs(); for (LogEvent logEvent : logs) { if (logEvent.getPriority().equals("INFO")) { String message = logEvent.getMessage(); if (message.contains("STATUS-Fault") && message.contains("404 Error: Not Found")) { errorLog = true; break; } } } } finally { post.releaseConnection(); } if (!errorLog) { fail("Response HTTP code not return successfully."); } }
From source file:org.wso2.carbon.esb.nhttp.transport.test.MessageWithoutContentTypeTestCase.java
/** * Sending a message without mentioning Content Type and check the body part at the listening port * <p/>/*from w w w . ja v a 2 s.c o m*/ * Public JIRA: WSO2 Carbon/CARBON-6029 * Responses With No Content-Type Header not handled properly * <p/> * Test Artifacts: ESB Sample 0 * * @throws Exception - if the scenario fail */ @SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL }) @Test(groups = "wso2.esb") public void testMessageWithoutContentType() throws Exception { // Get target URL String strURL = getMainSequenceURL(); // Get SOAP action String strSoapAction = "getQuote"; // Get file to be posted String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "synapseconfig" + File.separator + "messagewithoutcontent" + File.separator + "request.xml"; File input = new File(strXMLFilename); // Prepare HTTP post PostMethod post = new PostMethod(strURL); // Request content will be retrieved directly // from the input stream RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity); // consult documentation for your web service post.setRequestHeader("SOAPAction", strSoapAction); // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { int result = httpclient.executeMethod(post); // Display status code log.info("Response status code: " + result); // Display response log.info("Response body: "); log.info(post.getResponseBodyAsString()); } finally { // Release current connection to the connection pool once you are done post.releaseConnection(); } }
From source file:smartrics.rest.client.RestClientImpl.java
private RequestEntity configureFileUpload(String fileName) { final File file = new File(fileName); if (!file.exists()) { throw new IllegalArgumentException("File not found: " + fileName); }/*from ww w . jav a 2s . c o m*/ return new FileRequestEntity(file, "application/octet-stream"); }