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.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the// ww w.j a v a2 s. c om * {@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 testReaderIsReadableExpectedClassType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/classtype"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); assertEquals("echo:Helloecho:World", postMethod.getResponseBodyAsString()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the//w ww.j a va2 s.c o m * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method works when there is no generic entity type. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableNoGenericEntityType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/nogenericentity"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); String response = postMethod.getResponseBodyAsString(); assertEquals("echo:Hello\r\nWorld\r\n", response); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the//from w w w . j a v a2 s .c o m * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method works when there is no argument type specified on the generic * type. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableGenericEntityEmptyType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityempty"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the/*from www.j a v a 2 s . c om*/ * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method returns true when the expected argument type is specified on the * generic type. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableGenericEntityTypeCorrect() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityqueuestring"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); assertEquals("Hello thereWorld there", postMethod.getResponseBodyAsString()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the/* ww w . ja va 2s .com*/ * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method returns false when an unexpected argument type is specified on the * generic type. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableGenericEntityTypeIncorrect() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/genericentityqueueobject"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the/*from www.java 2 s.c o m*/ * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method still works without an annotated entity parameter. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableEntityParameterNotAnnotated() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/notannotatedentity"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); postMethod.addRequestHeader("Accept", "text/plain"); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the//from www .ja v a2s. com * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method is passed a single annotation. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableEntityParameterAnnotated() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/annotatedentity"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); postMethod.addRequestHeader("Accept", "text/plain"); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); assertEquals("text/plain", postMethod.getResponseHeader("Content-Type").getValue()); assertEquals("Hello thereWorld there", postMethod.getResponseBodyAsString()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the/*from w w w .j a v a 2 s. c o m*/ * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method is passed multiple annotations. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableEntityParameterAnnotatedMultiple() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/multipleannotatedentity"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); postMethod.addRequestHeader("Accept", "text/plain"); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); assertEquals("text/plain", postMethod.getResponseHeader("Content-Type").getValue()); assertEquals("Hello thereWorld there", postMethod.getResponseBodyAsString()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the//from w w w . ja v a 2 s . c o m * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method is passed an incompatiable media type and does not return true. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableIncorrectMediaType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/mediatype"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "text/plain", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.readers.JAXRSMessageBodyReadersTest.java
/** * Tests that the//from ww w . j av a 2s .c om * {@link MessageBodyReader#isReadable(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)} * method is passed the expected media type and reads the data. * * @throws HttpException * @throws IOException */ public void testReaderIsReadableCorrectMediaType() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/jaxrs/tests/providers/messagebodyreader/reader/mediatype"); postMethod.setRequestEntity(new StringRequestEntity("Hello\r\nWorld\r\n", "custom/type", "UTF-8")); try { client.executeMethod(postMethod); assertEquals(200, postMethod.getStatusCode()); String response = postMethod.getResponseBodyAsString(); assertTrue(response, response.contains("Hello there")); assertTrue(response, response.contains("World there")); } finally { postMethod.releaseConnection(); } }