Thursday, September 20, 2012
JAXBcontext inside servlet context
You are trying to unmarshall an xml to a class in tomcat deployed app.
The class you want to unmarshall to is in the included jar with the jaxb.index. But even then we get the error:
failed to unmarshall, cannot find jaxb.index
JAXB context inside servlet in tomcat. Because of classloader being different. If the classes being unmarshalled are in a dependent jar, it will not be caught by the class loader.JAXBContext get instance takes in the package to load and the classLoader where the package could be found.
ClassLoader cl = Content.class.getClassLoader();
jaxbContext = JAXBContext.newInstance("com...domain", cl);
Tuesday, July 10, 2012
Jersey ApacheHttpClient with connection pooling
Using Jersey ApacheHttpClient
When using the jersey client. Make use you use ApacheHttpClient instead of jersey client.
http://jersey.java.net/nonav/apidocs/1.2/contribs/jersey-apache-client/com/sun/jersey/client/apache/ApacheHttpClient.html
This is the standard way you get the client
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setConnectionTimeout(connectTimeout);
connectionManager.getParams().setSoTimeout(readTimeout);
connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
HttpClient httpClient = new HttpClient(connectionManager);
ApacheHttpClientHandler httpClientHandler = new ApacheHttpClientHandler(httpClient);
contentServerClient = new ApacheHttpClient(httpClientHandler);
contentServerClient.setConnectTimeout(connectTimeout);
contentServerClient.setReadTimeout(readTimeout);
once you get the client get the web resource from the uri
WebResource resource = getContentServerClient().resource(contentServerUrl).path("streets").path("6708NE");
try {
Street street = resource.get(Street.class);
} catch (UniformInterfaceException e) {
throw new NoContentFoundException("Can't locate street for Id " + kaniId);
}
Subscribe to:
Comments (Atom)