users@jersey.java.net

Re: [Jersey] ClientHandlerException When Applying HTTPD Basis Authentication

From: cgswtsu78 <cgray_at_proofpoint.com>
Date: Mon, 11 Jan 2010 09:07:00 -0800 (PST)

It looks like an attempt to go after the jersey resource again, throws a 401
(from ClientResponse.getStatus()). I have a few methods that call other
methods in the same resource so that I can reuse code. If I don't make
calls to the response ClientResponse then I'm ok. So maybe it's my httpd
setup that needs the fixing....

cgswtsu78 wrote:
>
> Hi Paul,
>
> I added client.addFilter(new LoggingFilter()); and it did yield some
> additional information about the response. The one thing that really
> doesn't make sense is that only some of my jersey apis fail. The failure
> seems directly tied to the response.getEntity method call. Any resource
> method with that fails with the ClientHandlerException. For example, see
> below. I get the same client response output in the log file whether it's
> a success or fail so I don't know how to interpret that output. Anything
> jump out to you?
>
> this one works (as I've just returned a new instance instead of making the
> response.getEntity call:
> @GET
> @Path(TOP_SPAM_SENDER_CHART)
> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> public Response getTopSpamSenderChart(@QueryParam("w") String width,
> @QueryParam("h") String height, @QueryParam("chartType") String chartType,
> @QueryParam("fromDate") String fromDate, @QueryParam("toDate") String
> toDate) throws Exception{
>
> Client client = Client.create();
> client.addFilter(new LoggingFilter());
> WebResource webResource = client.resource(ChartUtils.getURL() +
> BASE_RESOURCE_LOCATION);
> webResource.addFilter(new LoggingFilter());
> ClientResponse response =
> webResource.path(TOP_SPAM_SENDER_CHART).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
> chart);
> ImageDetails id = new ImageDetails();
> return Response.ok(id).build();
>
> this one fails with below exception:
> @GET
> @Path(TOP_SPAM_SENDER_CHART)
> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> public Response getTopSpamSenderChart(@QueryParam("w") String width,
> @QueryParam("h") String height, @QueryParam("chartType") String chartType,
> @QueryParam("fromDate") String fromDate, @QueryParam("toDate") String
> toDate) throws Exception{
> Client client = Client.create();
> client.addFilter(new LoggingFilter());
> WebResource webResource = client.resource(ChartUtils.getURL() +
> BASE_RESOURCE_LOCATION);
> webResource.addFilter(new LoggingFilter());
> ClientResponse response =
> webResource.path(TOP_SPAM_SENDER_CHART).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
> chart);
>
> return Response.ok(response.getEntity(ImageDetails.class)).build();
> }
>
> Client Response Logging:
> Jan 11, 2010 8:14:40 AM com.sun.jersey.api.client.filter.LoggingFilter log
> INFO: 1 * Client in-bound response
> 1 < 401
> 1 < WWW-Authenticate: Basic realm="Report Service"
> 1 < Date: Mon, 11 Jan 2010 16:14:40 GMT
> 1 < Vary: Accept-Encoding
> 1 < Content-Length: 401
> 1 < Keep-Alive: timeout=15, max=100
> 1 < Connection: Keep-Alive
> 1 < Content-Type: text/html; charset=iso-8859-1
> 1 < Server: Apache/2.2.9
> 1 <
> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
> <html><head>
> <title>401 Authorization Required</title>
> </head><body>
> <h1>Authorization Required</h1>
> <p>This server could not verify that you
> are authorized to access the document
> requested. Either you supplied the wrong
> credentials (e.g., bad password), or your
> browser doesn't understand how to supply
> the credentials required.</p>
> </body></html>
>
>
> Paul Sandoz wrote:
>>
>> Hi,
>>
>> I am guessing that for the case when auth is enabled that a different
>> response is returned from the server to the client API. If you enable
>> client logging (see [1]) you might be better able to know what is gong
>> on.
>>
>> Usually i would expect the client API to throw a UniformInterface
>> exception because 401 (Unauthorized) response would be returned.
>>
>> Paul.
>>
>>
>> [1]
>> https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/filter/ClientFilter.html
>>
>>
>> On Jan 11, 2010, at 4:11 AM, cgswtsu78 wrote:
>>
>>>
>>> Hello,
>>>
>>> Whenever I setup httpd basic authentication the below two resources
>>> fail and
>>> throw a ClientHandlerException (see details below) complaining about
>>> the
>>> media type not being found for ImageDetails. If I remove the httpd
>>> basic
>>> auth then both resource methods below work as expected. Anyone with
>>> any
>>> clues?
>>>
>>> Resources Class
>>> <code>
>>> @GET
>>> @Path("chart")
>>> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
>>> public Response getTopSpamSenderChart(@QueryParam("w") String width,
>>> @QueryParam("h") String height, @QueryParam("chartType") String
>>> chartType, @QueryParam("fromDate") String fromDate,
>>> @QueryParam("toDate")
>>> String toDate) throws Exception{
>>>
>>> TopSpamSenderChart chart = topSpamSenderService.populateChart(width,
>>> height,
>>> chartType, fromDate, toDate);
>>> Client client = Client.create();
>>> WebResource webResource = client.resource(ChartUtils.getURL() +
>>> BASE_RESOURCE_LOCATION);
>>> ClientResponse response =
>>> webResource
>>> .path
>>> (TOP_SPAM_SENDER_CHART
>>> ).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
>>> chart);
>>>
>>> return Response.ok(response.getEntity(ImageDetails.class)).build();
>>> }
>>>
>>> @GET
>>> @Path("chart")
>>> @Produces({"image/png"})
>>> public Response getTopSpamSenderChartAsImage(@QueryParam("w") String
>>> width,
>>> @QueryParam("h") String height, @QueryParam("chartType") String
>>> chartType,
>>> @QueryParam("fromDate") String fromDate, @QueryParam("toDate") String
>>> toDate) throws Exception{
>>>
>>> TopSpamSenderChart chart = topSpamSenderService.populateChart(width,
>>> height,
>>> chartType, fromDate, toDate);
>>>
>>> Client client = Client.create();
>>> WebResource webResource = client.resource(ChartUtils.getURL() +
>>> BASE_RESOURCE_LOCATION);
>>> ClientResponse response =
>>> webResource
>>> .path
>>> (TOP_SPAM_SENDER_CHART
>>> ).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
>>> chart);
>>>
>>> return
>>> Response
>>> .ok
>>> (getChartAsImage(response.getEntity(ImageDetails.class))).build();
>>> }
>>>
>>> ImageDetails.java
>>> import java.awt.Image;
>>> import java.io.Serializable;
>>>
>>> import javax.xml.bind.annotation.XmlRootElement;
>>>
>>> @XmlRootElement(name="ImageDetails")
>>> public class ImageDetails implements Serializable{
>>>
>>> private static final long serialVersionUID = 326449095657073079L;
>>> private Image image;
>>>
>>> public Image getImage() {
>>> return image;
>>> }
>>>
>>> public void setImage(Image image) {
>>> this.image = image;
>>> }
>>>
>>>
>>>
>>> }
>>> </code>
>>>
>>> web.xml
>>> <!DOCTYPE web-app PUBLIC
>>> "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>>> "http://java.sun.com/dtd/web-app_2_3.dtd" >
>>>
>>> <web-app>
>>> <display-name>Archetype Created Web Application</display-name>
>>>
>>> <servlet>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>>
>>> <servlet-
>>> class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-
>>> class>
>>> <init-param>
>>> <param-name>com.sun.jersey.config.property.packages</param-
>>> name>
>>> <param-value>com.proofpoint.reportsvcs.ws.impl</param-value>
>>> </init-param>
>>> <init-param>
>>>
>>> <param-name>com.sun.jersey.config.property.MediaTypeMappings</param-
>>> name>
>>> <param-value>json : application/json, xml : application/xml,
>>> stream
>>> : image/png</param-value>
>>> </init-param>
>>> <load-on-startup>1</load-on-startup>
>>> </servlet>
>>> <servlet-mapping>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>> <url-pattern>/jersey/*</url-pattern>
>>> </servlet-mapping>
>>>
>>> </web-app>
>>>
>>>
>>>
>>>
>>> Jan 10, 2010 6:22:05 PM com.sun.jersey.spi.container.ContainerResponse
>>> mapMappableContainerException
>>> SEVERE: The RuntimeException could not be mapped to a response, re-
>>> throwing
>>> to the HTTP container
>>> com.sun.jersey.api.client.ClientHandlerException: A message body
>>> reader for
>>> Java type, class com.proofpoint.reportsvcs.entities.ImageDetails,
>>> and MIME
>>> media type, text/html;charset=iso-8859-1, was not found
>>> at
>>> com
>>> .sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
>>> 526)
>>> at
>>> com
>>> .sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
>>> 491)
>>> at
>>> com
>>> .proofpoint
>>> .reportsvcs
>>> .ws
>>> .impl
>>> .TopSpamSenderWSImpl.getTopSpamSenderChart(TopSpamSenderWSImpl.java:
>>> 74)
>>> 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
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl.model.method.dispatch.AbstractResourceMethodDispatchProvider
>>> $
>>> ResponseOutInvoker
>>> ._dispatch(AbstractResourceMethodDispatchProvider.java:168)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .model
>>> .method
>>> .dispatch
>>> .ResourceJavaMethodDispatcher
>>> .dispatch(ResourceJavaMethodDispatcher.java:67)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .uri
>>> .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .server
>>> .impl
>>> .application
>>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
>>> at
>>> com
>>> .sun
>>> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
>>> 384)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .spi
>>> .container.servlet.ServletContainer.service(ServletContainer.java:451)
>>> at
>>> com
>>> .sun
>>> .jersey
>>> .spi
>>> .container.servlet.ServletContainer.service(ServletContainer.java:632)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>>> at
>>> org
>>> .apache
>>> .catalina
>>> .core
>>> .ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
>>> 290)
>>> at
>>> org
>>> .apache
>>> .catalina
>>> .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>> at
>>> org
>>> .apache
>>> .catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
>>> 233)
>>> at
>>> org
>>> .apache
>>> .catalina.core.StandardContextValve.invoke(StandardContextValve.java:
>>> 191)
>>> at
>>> org
>>> .apache
>>> .catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>>> at
>>> org
>>> .apache
>>> .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>>> at
>>> org
>>> .apache
>>> .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
>>> 109)
>>> at
>>> org
>>> .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
>>> 293)
>>> at
>>> org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
>>> at
>>> org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
>>> at
>>> org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
>>> at
>>> org
>>> .apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:
>>> 698)
>>> at
>>> org.apache.jk.common.ChannelSocket
>>> $SocketConnection.runIt(ChannelSocket.java:891)
>>> at
>>> org.apache.tomcat.util.threads.ThreadPool
>>> $ControlRunnable.run(ThreadPool.java:690)
>>> at java.lang.Thread.run(Thread.java:619)
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/ClientHandlerException-When-Applying-HTTPD-Basis-Authentication-tp4283615p4283615.html
>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>

-- 
View this message in context: http://n2.nabble.com/ClientHandlerException-When-Applying-HTTPD-Basis-Authentication-tp4283615p4286677.html
Sent from the Jersey mailing list archive at Nabble.com.