[ 
https://issues.apache.org/jira/browse/CLEREZZA-671?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Hasan closed CLEREZZA-671.
--------------------------

    
> JSONObjects returned by a JAX-RS resource method are not correctly processed 
> by the JSONObjectMessageBodyWriter if they contain 2-byte unicode characters, 
> e.g., umlauts
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CLEREZZA-671
>                 URL: https://issues.apache.org/jira/browse/CLEREZZA-671
>             Project: Clerezza
>          Issue Type: Bug
>          Components: platform
>            Reporter: Hasan
>            Assignee: Hasan
>
> The following tests with umlauts fail
> public class JSONObjectMessageBodyWriterTest {
>       @Path("/foo")
>       public class MyResource {
>               @Path("bar")
>               @GET
>               public JSONObject myMethod(@QueryParam("name") String name){
>                       JSONObject obj = new JSONObject();
>                       obj.put("name", name);
>                       return obj;
>               }
>       }
>       @Test
>       public void testMbwWithoutUmlaut() throws IOException {
>               testMbw("foobar");
>       }
>       @Test
>       public void testMbwWithUmlaut() throws IOException {
>               testMbw("foobär");
>       }
>       private void testMbw(String param) throws IOException {
>               final TestWebServer testWebServer = createTestWebServer(new 
> MyResource());
>               int port = testWebServer.getPort();
>               URL serverURL = new URL("http://localhost:"; + port + 
> "/foo/bar?name=" + param);
>               HttpURLConnection connection = (HttpURLConnection) 
> serverURL.openConnection();
>               connection.setRequestMethod("GET");
>               connection.addRequestProperty("Accept", "application/json, */*; 
> q=.2");
>               BufferedReader br = new BufferedReader(new 
> InputStreamReader(connection.getInputStream()));
>               String line = br.readLine();
> //            System.out.println(line);
>               Assert.assertEquals("{\"name\":\""+param+"\"}", line);
>               testWebServer.stop();
>       }
>       private TestWebServer createTestWebServer(final Object resource) {
>               return new TestWebServer(new Application() {
>                       @Override
>                       public Set<Class<?>> getClasses() {
>                               Set<Class<?>> result = new HashSet<Class<?>>();
>                               return result;
>                       }
>                       @Override
>                       public Set<Object> getSingletons() {
>                               Set<Object> result = new HashSet<Object>();
>                               result.add(resource);
>                               result.add(new JSONObjectMessageBodyWriter());
>                               return result;
>                       }
>               });
>       }
>       @Test
>       public void testWriteToAndGetSizeWithUmlaut() throws Exception {
>               testWriteToAndGetSize("foobär");
>       }
>       @Test
>       public void testWriteToAndGetSizeWithoutUmlaut() throws Exception {
>               testWriteToAndGetSize("foobar");
>       }
>       private void testWriteToAndGetSize(String name) throws Exception {
>               JSONObject value = new JSONObject();
>               value.put("name", name);
>               Class<?> type = null;
>               Type genericType = null;
>               Annotation[] annotations = null;
>               MediaType mediaType = null;
>               MultivaluedMap<String, Object> httpHeaders = null;
>               OutputStream out = new ByteArrayOutputStream();
>               JSONObjectMessageBodyWriter instance = new 
> JSONObjectMessageBodyWriter();
>               long size = instance.getSize(value, type, genericType, 
> annotations, mediaType);
> //            System.out.println(size);
>               instance.writeTo(value, type, genericType, annotations, 
> mediaType, httpHeaders, out);
>               long len = out.toString().getBytes("UTF-8").length;
> //            System.out.println(out.toString());
> //            System.out.println(len);
>               Assert.assertEquals(size, len);
>       }
> }
> Test output
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest
> 106 [main] INFO org.apache.clerezza.triaxrs.JaxRsHandler - Binding 
> application config: 
> org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest$1@ccc588 
> (class org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest$1)
> 232 [main] INFO org.eclipse.jetty.util.log - Logging to 
> org.slf4j.impl.SimpleLogger(org.eclipse.jetty.util.log) via 
> org.eclipse.jetty.util.log.Slf4jLog
> 257 [main] INFO org.eclipse.jetty.util.log - jetty-7.0.1.v20091125
> 321 [main] INFO org.eclipse.jetty.util.log - Started 
> [email protected]:8100
> 659 [main] INFO org.apache.clerezza.triaxrs.JaxRsHandler - Binding 
> application config: 
> org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest$1@1a0225b 
> (class org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest$1)
> 662 [main] INFO org.eclipse.jetty.util.log - jetty-7.0.1.v20091125
> 669 [main] INFO org.eclipse.jetty.util.log - Started 
> [email protected]:8100
> 677 [qtp19589694-21] WARN org.apache.clerezza.triaxrs.JaxRsHandler - 
> Exception (with no exception mapper)
> java.io.IOException: Closed
>         at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:138)
>         at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:86)
>         at 
> java.nio.channels.Channels$WritableByteChannelImpl.write(Channels.java:296)
>         at 
> org.wymiwyg.wrhapi.jetty.FirstWriteOrCloseActionChannel.write(FirstWriteOrCloseActionChannel.java:46)
>         at java.nio.channels.Channels.writeFullyImpl(Channels.java:59)
>         at java.nio.channels.Channels.writeFully(Channels.java:84)
>         at java.nio.channels.Channels.access$000(Channels.java:47)
>         at java.nio.channels.Channels$1.write(Channels.java:155)
>         at java.io.OutputStream.write(OutputStream.java:58)
>         at java.nio.channels.Channels$1.write(Channels.java:136)
>         at 
> org.apache.clerezza.triaxrs.util.FirstByteActionOutputStream.write(FirstByteActionOutputStream.java:46)
>         at java.io.OutputStream.write(OutputStream.java:99)
>         at java.io.OutputStream.write(OutputStream.java:58)
>         at 
> org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriter.writeTo(JSONObjectMessageBodyWriter.java:72)
>         at 
> org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriter.writeTo(JSONObjectMessageBodyWriter.java:43)
>         at 
> org.apache.clerezza.triaxrs.ResponseProcessor$1.writeTo(ResponseProcessor.java:333)
>         at 
> org.apache.clerezza.triaxrs.ResponseProcessor$1.writeTo(ResponseProcessor.java:326)
>         at 
> org.wymiwyg.wrhapi.jetty.JettyWebServerFactory$2.handle(JettyWebServerFactory.java:113)
>         at 
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
>         at org.eclipse.jetty.server.Server.handle(Server.java:334)
>         at 
> org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559)
>         at 
> org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:992)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:541)
>         at 
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
>         at 
> org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406)
>         at 
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462)
>         at 
> org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
>         at java.lang.Thread.run(Thread.java:619)
> Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.805 sec <<< 
> FAILURE!
> Results :
> Failed tests: 
>   
> testMbwWithUmlaut(org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest)
>   
> testWriteToAndGetSizeWithUmlaut(org.apache.clerezza.jaxrs.utils.JSONObjectMessageBodyWriterTest)
> Tests run: 4, Failures: 2, Errors: 0, Skipped: 0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to