List of usage examples for org.apache.commons.httpclient.methods StringRequestEntity StringRequestEntity
public StringRequestEntity(String paramString)
From source file:org.apache.servicemix.http.security.HttpSecurityTest.java
public void testWSSecBadCred() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileUtil.copyInputStream(getClass().getResourceAsStream("request-bc.xml"), out); String request = out.toString(); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://localhost:8192/WSSec/"); try {//w ww. ja v a2 s .c o m method.setDoAuthentication(true); method.setRequestEntity(new StringRequestEntity(request)); int state = client.executeMethod(method); String str = method.getResponseBodyAsString(); log.info(str); assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state); Element e = new SourceTransformer().toDOMElement(new StringSource(str)); assertEquals("Envelope", e.getLocalName()); e = (Element) e.getFirstChild(); assertEquals("Body", e.getLocalName()); e = (Element) e.getFirstChild(); assertEquals("Fault", e.getLocalName()); } finally { method.releaseConnection(); } }
From source file:org.apache.servicemix.http.security.HttpSecurityTest.java
public void testWSSecUnkownUser() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileUtil.copyInputStream(getClass().getResourceAsStream("request-uu.xml"), out); String request = out.toString(); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://localhost:8192/WSSec/"); try {/*from ww w . ja v a2s . c o m*/ method.setDoAuthentication(true); method.setRequestEntity(new StringRequestEntity(request)); int state = client.executeMethod(method); String str = method.getResponseBodyAsString(); log.info(str); assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state); Element e = new SourceTransformer().toDOMElement(new StringSource(str)); assertEquals("Envelope", e.getLocalName()); e = (Element) e.getFirstChild(); assertEquals("Body", e.getLocalName()); e = (Element) e.getFirstChild(); assertEquals("Fault", e.getLocalName()); } finally { method.releaseConnection(); } }
From source file:org.apache.servicemix.http.ServerManagerTest.java
private String requestWithHttpClient(String url, String content) throws Exception { HttpMethod method;/*from w ww . ja v a 2 s. c o m*/ if (content != null) { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(content)); method = post; } else { GetMethod get = new GetMethod(url); method = get; } new HttpClient().executeMethod(method); if (method.getStatusCode() != 200) { throw new InvalidStatusResponseException(method.getStatusCode()); } return method.getResponseBodyAsString(); }