users@jersey.java.net

Re: [Jersey] An error seen with a test run against HTTPServer when run on Windows

From: Srinivas Naresh Bhimisetty <Srinivas.Bhimisetty_at_Sun.COM>
Date: Tue, 18 Nov 2008 09:39:27 +0530

Upon adding the logging filter, I see this in the console:
=======================================================
INFO: Provider classes found:
  class com.sun.jersey.qe.tests.jmaki.config.JAXBContextResolver
1 * Out-bound request
1 > GET http://localhost:9998/jMakiBackend/webresources/printers/ids/P01
1 > Accept: application/json
1 >
1 < -1
1 < Content-type: unknown/unknown
1 <
0

HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: application/json

42
{"id":"P01","model":"Xerox","url":"room 1","location":"lpd://p01"}
0


1 * In-bound response
==============================================================

  For some reason the resource is setting the content-type to
"unknown/unknown"(and this is only for HTTPServer and that too only in
Windows).

-Naresh

Paul Sandoz wrote:
> Out of ideas... need more data :-)
>
> Like what is on the wire. Perhaps you can use the client logging filter:
>
> com.sun.jersey.api.client.filter.LoggingFilter
>
> add an instance of that to the WebResource instance.
>
> Paul.
>
> On Nov 17, 2008, at 4:45 PM, Srinivas Naresh Bhimisetty wrote:
>
>> Srinivas Naresh Bhimisetty wrote:
>>>
>>> Paul Sandoz wrote:
>>>> Hi,
>>>>
>>>> My guess is that the client thinks the representation returned is
>>>> XML, when it is actually JSON.
>>>>
>>>> I would check carefully the accept header the client is sending to
>>>> the server. It could be that in windows the default accept header
>>>> created by HttpURLConnection is different on Windows than on other
>>>> platforms. And the client test code needs to explicitly set the
>>>> accept header.
>>> Okay Paul. I shall try doing this.
>> I did check it, and actually the accept header is already set to
>> "application/json".
>> Here is the code fragment:
>> ====================================================
>> 1>> Printer printer = r.path("printers").path("ids").path("P01")
>> .accept(MediaType.APPLICATION_JSON).get(Printer.class);
>> String printerModel = printer.model;
>> String printerLocation = printer.location;
>> String printerUrl = printer.url;
>> printer = new Printer("P01", "Xerox", printerLocation,
>> printerUrl);
>> ClientResponse response =
>> r.path("printers").path("ids").path("P01")
>>
>> .type(MediaType.APPLICATION_JSON).put(ClientResponse.class, printer);
>> Assert.assertEquals("Method: doTestPutPrinterBasedOnId
>> \nMessage: Response status doesn't match the expected value.",
>> Response.Status.NO_CONTENT,
>> response.getResponseStatus());
>> *2>> printer = r.path("printers").path("ids").path("P01")
>> .accept(MediaType.APPLICATION_JSON).get(Printer.class);
>> * Assert.assertNotSame("Method: doTestPutPrinterBasedOnId
>> \nMessage: Printer holds the old model inspite of update.",
>> printerModel, printer.model);
>> ====================================================
>>
>> The error is thrown in the second GET request sent by the client.
>> And looks like the same request had gone through without any error in
>> the first call at "1>>".
>>
>> -Naresh
>>
>>>
>>> -Naresh
>>>>
>>>> Paul.
>>>>
>>>> On Nov 14, 2008, at 2:09 PM, Srinivas Naresh Bhimisetty wrote:
>>>>
>>>>> Hi Paul,
>>>>>
>>>>> as you might have noticed I have created a branch called
>>>>> "jersey-test-framework" for the Jersey Testing Framework development.
>>>>> I see one issue with the jMaki Backend tests which were ported to
>>>>> this branch. These tests run fine with the three containers
>>>>> EmbeddedGF, Grizzly and HTTPServer on Ubuntu, but on my Windows
>>>>> laptop one test fails when run with HTTPServer. It gives the
>>>>> following error:
>>>>>
>>>>> ============================================================================================
>>>>>
>>>>> doTestPutPrinterBasedOnId(com.sun.jersey.qe.tests.jmaki.JMakiBackendWebappTest)
>>>>> Time elapsed: 0.057 sec <<< ERROR!
>>>>> javax.ws.rs.WebApplicationException:
>>>>> javax.xml.bind.UnmarshalException
>>>>> - with linked exception:
>>>>> [org.xml.sax.SAXParseException: Content is not allowed in prolog.]
>>>>> at
>>>>> com.sun.jersey.impl.provider.entity.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:93)
>>>>>
>>>>> at
>>>>> com.sun.jersey.impl.client.urlconnection.URLConnectionClientHandler$URLConnectionResponse.getEntity(URLConnectionClientHandler.java:156)
>>>>>
>>>>> at
>>>>> com.sun.jersey.impl.client.urlconnection.URLConnectionClientHandler$URLConnectionResponse.getEntity(URLConnectionClientHandler.java:138)
>>>>>
>>>>> at
>>>>> com.sun.jersey.api.client.WebResource.handle(WebResource.java:466)
>>>>> at
>>>>> com.sun.jersey.api.client.WebResource.access$200(WebResource.java:64)
>>>>> at
>>>>> com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:356)
>>>>>
>>>>> at
>>>>> com.sun.jersey.qe.tests.jmaki.JMakiBackendWebappTest.doTestPutPrinterBasedOnId(JMakiBackendWebappTest.java:257)
>>>>>
>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>
>>>>> at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>
>>>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>>> at
>>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>>
>>>>> at
>>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>>
>>>>> at
>>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>>
>>>>> at
>>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>>
>>>>> at
>>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>>
>>>>> at
>>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>>
>>>>> at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>>>>>
>>>>> at
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
>>>>> at
>>>>> org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
>>>>> at
>>>>> org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
>>>>> at
>>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>>
>>>>> at
>>>>> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>>>>>
>>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>>>>> at
>>>>> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>>>>>
>>>>> at
>>>>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>>>>>
>>>>> at
>>>>> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>>>>>
>>>>> at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>> at
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>>>>
>>>>> at
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>>>>
>>>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>>>> at
>>>>> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
>>>>>
>>>>> at
>>>>> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
>>>>>
>>>>> Caused by: javax.xml.bind.UnmarshalException
>>>>> - with linked exception:
>>>>> [org.xml.sax.SAXParseException: Content is not allowed in prolog.]
>>>>> at
>>>>> javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
>>>>>
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:481)
>>>>>
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:199)
>>>>>
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
>>>>>
>>>>> at
>>>>> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
>>>>>
>>>>> at
>>>>> javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
>>>>>
>>>>> at
>>>>> com.sun.jersey.impl.provider.entity.XMLRootElementProvider.readFrom(XMLRootElementProvider.java:92)
>>>>>
>>>>> at
>>>>> com.sun.jersey.impl.provider.entity.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:91)
>>>>>
>>>>> ... 34 more
>>>>> Caused by: org.xml.sax.SAXParseException: Content is not allowed
>>>>> in prolog.
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1411)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1038)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
>>>>>
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
>>>>>
>>>>> at
>>>>> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
>>>>>
>>>>> ... 39 more
>>>>> ==============================================================================================
>>>>>
>>>>>
>>>>> Is it possible that this is some Windows specific issue?
>>>>>
>>>>> Thanks,
>>>>> Naresh
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> <mailto:users-unsubscribe_at_jersey.dev.java.net> For additional
>> commands, e-mail: users-help_at_jersey.dev.java.net
>> <mailto:users-help_at_jersey.dev.java.net>
>