please help me on solving issue java.lang.ClassCastException? [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed yesterday.
Improve this question
Please help me what might be reason for this issue ? I think instead of taking the servlet class from jaxws, it is taking from ibm jdk. but not able to find the exact root cause and solve it.
[INFO ] FFDC1015I: An FFDC Incident has been created: "java.lang.ClassCastException: com.sun.xml.ws.transport.http.servlet.WSServlet incompatible with javax.servlet.Servlet com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet 213" at ffdc_23.02.18_12.04.17.0.log
[ERROR ] SRVE0276E: Error while initializing Servlet [load]: javax.servlet.UnavailableException: SRVE0201E: Servlet [com.sun.xml.ws.transport.http.servlet.WSServlet]: not a servlet class
at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1553)
at [internal classes]
I am using eclipse and gradle build. Added classloader delegation="parentLast" in server.xml and changed the order in build path moving jaxws jars on top. Still facing the same issue
web.xml
<servlet>
<servlet-name>load</servlet-name>
<servlet-
class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>load</servlet-name>
<url-pattern>/load</url-pattern>
</servlet-mapping>
corresponding Load.java
#WebService
public class Load {
#WebMethod
public AFRLoadResponse loadAFRRecord(
#WebParam(name="loadRecordCriteria",targetNamespace = "")
LoadRecordCriteria loadRecordCriteria,
#WebParam(name="systemCredentials",targetNamespace = "")
SystemCredentials sysCreds) throws LoadException {
//
app specific code and response preparation
//
return loadResponse;
}
}

Related

How can I Load a class while startup tomcat Server [duplicate]

This question already has an answer here:
Using special auto start servlet to initialize on startup and share application data
(1 answer)
Closed 1 year ago.
I would like to load java class file that contain db related function. How can I load that java file while starting the tomcat server
you can use servlet for that as below, define into web.xml
<servlet>
<servlet-name>YourServletName</servlet-name>
<servlet-class>com.abc.xyz.YourServletClassName</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
in YourServletClassName.java file you can write your code.
Hope it helps you.
The answer by Psabuwala is correct but not complete.
Code that will run on startup should be placed in the init method of the servlet.
Web.xml:
...
<servlet>
<servlet-name>mainServlet</servlet-name>
<servlet-class>example.com.MainServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
MainServlet.java:
public class MainServlet extends HttpServlet
{
public void init() throws ServletException
{
DataLoader dataLoader = new DataLoader();
dataLoader.load();
}
...
}

RESTEasy Could not find MessageBodyWriter - Jackson Configured

I recently set up RESTEasy on Tomcat 7. We do not use Maven. I mention this early on, because all of the answers I've found to my question to date suggest adding a reference to the pom.xml. Adding references to my project, so far, hasn't solved my problem (but, maybe I'm missing something).
At this point, I'm just trying to recreate the out-of-the-box examples I've seen online where I should be able to correctly annotate a POJO, and return it as JSON using RESTEasy, assuming I have my build configured correctly. My build references:
- jackson.core.asl
- jackson.jaxrs
- jackson.mapper.asl
and all the required RESTEasy jars. In fact, I can successfully obtain the JSON I want from a GET if I return a Response (as in the example I found here: RestEasy: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/json). Of course, that's not using Jackson through RESTEasy, at all.
Whenever I try to return an object, however, of any kind, I get:
Could not find MessageBodyWriter for response object of type: ... application/json
I'm not sure what I'm doing wrong, as all the answers I can find suggest that what I need to do is make sure that jackson is correctly referenced---which, from all I can tell, it is. Below is the relevant portion of my web.xml.
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>rest_services.RootRestService</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/services</param-value>
</context-param>
Here is my Service method:
#GET
#Path("/getTables")
#Produces(MediaType.APPLICATION_JSON)
public List<MyTable> getTables() {
...
}
Here is the class it's returning:
#XmlRootElement
public final class MyTable {
...
}
EDIT :
Here are the classes I added to my classpath (and a few others)
:
Any help is greatly appreciated.
I was never able to get Jackson working, but I switched to Jettison, and all works fine. This is good enough for me, for now.

Error trying to call method from server on GWT

I'm trying to call a method from my server side whose signature is
public Integer method()
but when I redid all the steps used on the StockWatcher tutorial to call it, I'm getting a 404 error which says this is the URL
<p>RequestURI=/com.medtronic.empattendance.EmployeeAttendance/empQueries</p>
I'm not sure what the correct URL should be, but this is the incorrect URL.
my web.xml says this on servlets
<servlet>
<servlet-name>empQueryServerImpl</servlet-name>
<servlet-class>com.medtronic.empattendance.server.EmpQueryServerImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>empQueryServerImpl</servlet-name>
<url-pattern>/empattendance/empQueries</url-pattern>
</servlet-mapping>
Where am I going wrong?
There is an alternative: Use the #RemoteServiceRelativePath (javadoc) annotation on your RPC class (The interface extending RemoteService, not the Async one).
Assuming your GWT app is /empattendance:
#RemoteServiceRelativePath("empQueries")
public interface EmpQueryServer extends RemoteService {
// your methods
}
I have solved it:
I had <url-pattern>/empattendance/empQueries</url-pattern> which was based off the tutorial, but digging deeper I found out I needed to use the full package name.
<url-pattern>/com.myCompany.empattendance.EmployeeAttendance/empQueries</url-pattern>

JSF 1.2 Exception Handling

I am working on exception handling in our Application. I used try catch blocks to catch the exceptions occured in my code and i also could handle the time out exceptions by writing a listener and registering the listener in "faces-config.xml".
But i am facing problems in catching unexpected errors like "NullPointerException" in constructor or error Codes 500, 400 etc.
i used the tags in the "web.xml"
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/sc00/ErrorPage.jsp</location>
</error-page>
I tried many ways to handle the exceptions, can any one help me in finding out a solution. The error i am getting when i try to handle these exceptions is as follows.
I am using JSF 1.2 and the server is websphere 8
The Console shows the Following Exception.
com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException
E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/sc00/ErrorPage.jsp] in application [MembershipEligibilityScreensEAR]. Exception created : [java.lang.RuntimeException: FacesContext not found
My Error Page is in /WebContent/sc00/ErrorPage.jsp, ErrorPage.jsp has no backing bean associated with it.
Many solutions asked me to look at the URL path of Faces Servlet, In My web.xml the servlet-mapping is a follows
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
all the paths in my faces-config.xml refer to /FolderName/JspName and they work fine and they work fine even in Navigation.xml.
How can i navigate it to ErrorPage.jsp, Is there any way so that i can write a listener to this kind of problem
Sorry for posting too many redundant questions, i am new to JSF and i don't know the rules of StackOverflow, I apologize for the problem i have caused.
any solution would be appreciated.
java.lang.RuntimeException: FacesContext not found
That will happen when you're requesting a JSP page containing JSF components through an URL which doesn't match the URL pattern of the FacesServlet (who is the one responsible for creating the FacesContext).
You need to change the error page location to match the URL pattern of the FacesServlet as definited in web.xml. Based on your duplicate questions on the subject, this is among others *.faces, so setting the error page location as follows should do, exactly as I suggested in a comment on your first question on the subject.
<location>/sc00/ErrorPage.faces</location>

Message level Jax-WS service

I'm trying to create a WebService stub. I like to react to all of the request in one single place. I have a sample value generator, which handles the type of the request and creates a sample response, so I don't need the code-generation things with a lots of classes. Only a really simple one.
I have found http://jax-ws.java.net/nonav/2.2.1/docs/provider.html WebServiceProvider which is exactly for getting raw SOAP messages, and create a response in a single place.
The main problem is I'm new to this magical EE world :) and I simply can not start WebServiceProvider sample anyway.
I have Spring, SpringSource ToolSuit, Axis installed/configured, all of the other things are working.
Thank you all for your help, and please excuse me if the question is too simple for you. Maybe I just did not find/read something.
M.
Finally I have found the solution (thanks for the help from my workmates).
If you are using JAX-WS, there is a simple solution.
You need a sun-jaxws.xml in your WEB-INF folder containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint
name="RawWS"
implementation="com.stg.pack.MyServiceProvider"
url-pattern="/HotelServices200631"/>
</endpoints>
And you need a com.stg.pack.MyServiceProvider class which looks like:
package com.stg.pack;
#ServiceMode(value = Service.Mode.MESSAGE)
#WebServiceProvider(portName = "ThePortNameOfWebService",
serviceName = "TheNameOfWebService",
targetNamespace = "http://www.example.com/target/namespace/uri")
public class MyServiceProvider implements Provider<SOAPMessage> {
#Override
public SOAPMessage invoke(SOAPMessage request) {
SOAPMessage result = null;
// create response SOAPMessage
return result;
}
}
And before I forget, you need to define some things in web.xml:
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>RawWS</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RawWS</servlet-name>
<url-pattern>/TheNameOfWebService</url-pattern>
</servlet-mapping>
If you use it like this, all of the request are handled by the invoke method.
you basically must deploy your provider to some sort of Container. developing in J/EE basically mandates that you compile some sort of EAR or WAR or JAR and tell an app server to deploy it (be that app server a JBOSS, glassfish, Weblogic, Websphere, Tomcat, etc).
Have you tried doing this?
it also may be possible to test your provider using the javax.xml.ws.Endpoint class, although I have to admit I've never chosen to per-sue this in favor of deploying to an app server.

Categories