List of usage examples for org.apache.commons.httpclient.methods StringRequestEntity StringRequestEntity
public StringRequestEntity(String paramString1, String paramString2, String paramString3) throws UnsupportedEncodingException
From source file:org.apache.wink.itest.param.formproperty.FormPropertyValidationTest.java
/** * {@link FormParam} annotated JavaBean property methods are not supported. * /*www . jav a 2 s. c o m*/ * @throws Exception */ public void testFormPropertyNoMultivaluedMapEntityValidation() throws Exception { HttpClient httpclient = new HttpClient(); PostMethod httpMethod = new PostMethod( getBaseURI() + "/params/form/validate/propertynotmultivaluedmaparam"); try { StringRequestEntity s = new StringRequestEntity("firstkey=somevalue&someothervalue=somethingelse", "application/x-www-form-urlencoded", null); httpMethod.setRequestEntity(s); httpclient.executeMethod(httpMethod); assertEquals(200, httpMethod.getStatusCode()); assertEquals("null:firstkey=somevalue&someothervalue=somethingelse", httpMethod.getResponseBodyAsString()); } finally { httpMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that an exception thrown from the * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method which is not mapped to an {@link ExceptionMapper} is still thrown. * //from ww w. ja va 2 s. c om * @throws HttpException * @throws IOException */ public void testIsReadableExceptionThrownWhichIsNotMappedIsThrownOut() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity(new StringRequestEntity("ignored input", "readable/throwruntime", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(500, postMethod.getStatusCode()); // assertLogContainsException("javax.servlet.ServletException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that an exception thrown from the * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method which is mapped to an {@link ExceptionMapper} uses the mapper. * //from w w w.j av a 2s. c o m * @throws HttpException * @throws IOException */ public void testIsReadableExceptionThrownWhichIsMappedUsesExceptionMapper() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity(new StringRequestEntity("ignored input", "readable/thrownull", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(495, postMethod.getStatusCode()); assertEquals("Invoked" + NullPointerExceptionMapper.class.getName(), postMethod.getResponseBodyAsString()); assertEquals("text/plain", postMethod.getResponseHeader("Content-Type").getValue()); // assertLogContainsException("NullPointerException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that a {@link WebApplicationException} thrown from the * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method is correctly processed./*from w w w.j a va2 s . c o m*/ * * @throws HttpException * @throws IOException */ public void testIsReadableWebApplicationExceptionThrown() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity( new StringRequestEntity("ignored input", "readable/throwwebapplicationexception", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(499, postMethod.getStatusCode()); assertEquals("can not read type", postMethod.getResponseBodyAsString()); // assertEquals("application/octet-stream", // postMethod.getResponseHeader("Content-Type").getValue()); // assertLogContainsException("WebApplicationException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that an exception thrown from the * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} * method which is not mapped to an {@link ExceptionMapper} is still thrown. * // www . j a va2 s .co m * @throws HttpException * @throws IOException */ public void testReadFromExceptionThrownWhichIsNotMappedIsThrownOut() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity(new StringRequestEntity("ignored input", "readfrom/throwruntime", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(500, postMethod.getStatusCode()); // assertLogContainsException("javax.servlet.ServletException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that an exception thrown from the * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} * method which is mapped to an {@link ExceptionMapper} uses the mapper. * // ww w . j a va2s.co m * @throws HttpException * @throws IOException */ public void testReadFromExceptionThrownWhichIsMappedUsesExceptionMapper() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity(new StringRequestEntity("ignored input", "readfrom/thrownull", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(495, postMethod.getStatusCode()); assertEquals("Invoked" + NullPointerExceptionMapper.class.getName(), postMethod.getResponseBodyAsString()); assertEquals("text/plain", postMethod.getResponseHeader("Content-Type").getValue()); // assertLogContainsException("NullPointerException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that a {@link WebApplicationException} thrown from the * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} * method is correctly processed.//from w w w.j a va2 s.c om * * @throws HttpException * @throws IOException */ public void testReadFromWebApplicationExceptionThrown() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity( new StringRequestEntity("ignored input", "readfrom/throwwebapplicationexception", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(498, postMethod.getStatusCode()); assertEquals("can not read type in readfrom", postMethod.getResponseBodyAsString()); // assertEquals("application/octet-stream", // postMethod.getResponseHeader("Content-Type").getValue()); // assertLogContainsException("WebApplicationException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readerexceptions.JAXRSMessageBodyReaderExceptionsTest.java
/** * Tests that a {@link IOException} thrown from the * {@link MessageBodyReader#readFrom(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream)} * method can be mapped correctly.//from w ww . j a v a2 s. co m * * @throws HttpException * @throws IOException */ public void testReadFromIOExceptionThrown() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/messagebodyreaderexceptions"); postMethod.setRequestEntity(new StringRequestEntity("ignored input", "readfrom/throwioexception", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(455, postMethod.getStatusCode()); assertEquals("Invoked" + IOExceptionMapper.class.getName(), postMethod.getResponseBodyAsString()); // assertEquals("application/octet-stream", // postMethod.getResponseHeader("Content-Type").getValue()); // assertLogContainsException("IOException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that an improperly formatted request content type is handled. * /*from www .j a v a2 s . co m*/ * @throws HttpException * @throws IOException */ public void testReaderImproperlyFormattedContentType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/requestcontenttype"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(500, postMethod.getStatusCode()); // assertLogContainsException("java.lang.IllegalArgumentException"); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the// ww w . ja va 2 s .com * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method receives the correct class type. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableUnexpectedClassType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/unexpectedclasstype"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }