users@jersey.java.net

[Jersey] ClientHandlerException When Applying HTTPD Basis Authentication

From: cgswtsu78 <cgray_at_proofpoint.com>
Date: Sun, 10 Jan 2010 19:11:45 -0800 (PST)

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.