Websphere - javax.servlet.UnavailableException: Servlet not a servlet class - servlets

I get this error message when trying to connect to our webservices.
Error 404: javax.servlet.UnavailableException: SRVE0201E: Servlet [...] not a servlet class.
However, the class mentioned inside the brackets is a servlet class:
#WebService(serviceName = "xxx", endpointInterface = "xxx")
What I read was that in Websphere the class loader should be configured to Parent last; this is what I did and then to get rid of all jar - files that use Servlet.jar - I think I did this, too, since the only files that I am using are these ones:
antisamy-1.4.3.jar
api-7.9.0.0.jar
avalon-framework-4.1.3.jar
batik-css-1.7.jar
batik-ext-1.7.jar
batik-util-1.7.jar
bsh-core-2.0b4.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.7.0.jar
commons-codec-1.2.jar
commons-collections-3.2.jar
commons-configuration-1.5.jar
commons-digester-1.8.jar
commons-fileupload-1.2.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
core-7.9.0.0.jar
dom4j-1.6.1.jar
esapi-2.0_rc11.jar
istack-commons-runtime-2.16.jar
jaxb-api-2.2.9.jar
jaxb-core-2.2.8-b01.jar
jaxb-impl-2.2-promoted-b65.jar
jaxen-1.1-beta-8.jar
jdom-1.0.jar
log4j-1.2.16.jar
log4j-api-2.7.jar
log4j-core-2.7.jar
logkit-1.0.1.jar
nekohtml-1.9.12.jar
serializer-2.7.2.jar
xalan-2.7.2.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
xml-apis-ext-1.3.04.jar
xom-1.1.jar
Maybe someone could give me a hint or knows that the problem can be?
Thank you very much!

If you're relying on the annotation you mentioned, that's going to create a web service, not a servlet. Unless of course the class the #WebService is defined in extends javax.servlet.Servlet. Did you mean #WebServlet instead? Posting the pertinent portion of your source would be helpful.

This is one possibility:
https://developer.ibm.com/answers/questions/171243/srve0201e-servlet-my-webservice-not-a-servlet-clas.html
This text in particular:
The issue was showing up at deploy time and had to do with the fact
that my web services was referencing classes in a shared library. The
deploy code doesn't have access to the shared library so it wasn't
able to resolve things and gave up.
After some mad refactoring it started working.

Related

CQ5 SlingServlet and resourceTypes not working for specific resource paths

If I define a Sling Servlet as follows:
#SlingServlet(
label="TestResourceTypeServlet",
name = "com.company.project.servlets.TestResourceType",
extensions = {"bob"},
resourceTypes= {"cq:Page"},
methods= {"GET"},
metatype=true)
#Properties({
#Property(name = "service.description", value = "A test servlet"),
#Property(name = "service.vendor", value = "Company")
})
The servlet picks up any get request to every page with an extension of '.bob', which is fine but what I really want is to handle a request to a specific page type,
SO
I modify resourceTypes to read
resourceTypes= {"site-administration/components/page/page-distribution"},
the supplied value is the specific sling:resourceType (copied and pasted out of CRXDE Lite) of a page I am trying to access with the .bob extension, but I get a 404!!!
All the documentation I've read says the above should work, but it does not.
Out of desperation I've even tried "site-administration/components/page" which is the super type of the page I want.
I'm running a clean 5.6.1 instance with this servlet as part of an OSGi bundle.
Am I missing something obvious here, or if not is anyone aware of any hot fixes that could resolve this issue ?
Any help would be appreciated as I'm starting to go slightly mad in the head.
EDIT
Ok, so I've gotten a little further: If I access the page with:
[path-to-page]/page.bob.html
The servlet fires. But in this URL is bob not a selector? and if so why when the resource type is cq:Page does the configuration work with bob as an extension?
Very confused :-S
I'm obviously missing something very simple here.
The problem with pages is that the resourceType is stored on the jcr:content node below the cq:Page node. If you would call [path-to-page]/_jcr_content.bob it should work. Note: _jcr_content is an url save version of jcr:content.
Why your last example is actually working, I cannot tell.

JDO + datanucleus API enhancement

I want to load dynamically XML meta-data files that are not in the classpath (the XML meta-data files will be generated after launching my app).
I thought I could call the method
MetaDataManager.registerFile(java.lang.String fileURLString, FileMetaData filemd, ClassLoaderResolver clr)
Then, I tried the API enhancement, so I added the following lines:
JDOEnhancer enhancer = JDOHelper.getEnhancer();
enhancer.setVerbose(true);
enhancer.addClasses(ClassToPersist.class.getName()).enhance();
getClass().getClassLoader().loadClass(ClassToPersist.class.getName());
The following jars are in the classpath: datanucleus-api-jdo.jar, datanucleus-connectionpool.jar, datanucleus-core.jar datanucleus-rdbms.jar, jdo-api.jar, asm.jar.
But when I launch my app, I get this exception:
Caused by: mypackage.MyException:
org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class "mypackage.ClassToPersist" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
Do you please have any idea how to fix this ?
PS: I also noticed that the method enhance returns 0 which indicates that the class has not been enhanced (we could exclude the other options)
Thanks
I think I found an easy way to fix this.
At runtime, I created a jar that contains the updated metadata file as META-INF/package.jdo. Then I added this jar to the classpath as described here
Using this hacks, I didn't need to re-enhace my class since it is enhanced after compilation.
(But for information, I had to call JDOEnhancer.addFiles() to enhance my class.)
So your call to loadClass has loaded the unenhanced class (since it would have been loaded in order to perform the enhancement presumably), and you didn't follow the tutorial that is provided at http://www.datanucleus.org/documentation/development/dynamic_class_metadata_enhance_runtime.html

The type 'foo.Info.AgentDetails' exists in both 'foo.dll' and 'foo.dll'

In my asp.net web application, one of my page, I am storing a list of objects(List<AgentDetails>) to ViewState. After that when I try to get it back as (List<AgentDetails>)ViewState["ViewStateAgentDetails"], i gets an error like
The type 'foo.Info.AgentDetails' exists in both 'foo.dll' and 'foo.dll'
I can't understand what is happening here.
I got stuck with this issue.
Could anybody help me out of this?
Thanks in advance.
If i interpret it correctly from answer to my comment, i can see that there might be some other DLL , that can have different dll name says bar.dll, but ultimately has same namespace and class name. So to fix this , find that second DLL, and use extern or change namespace to solve this error.
More explanation - http://blogs.msdn.com/b/abhinaba/archive/2005/11/30/498278.aspx
How do you allow two DLL's with same namespace.class to exist in the same application?

Webservlet urlpatterns for index.jsp

I'm stuck with this problem and I can't find a solution for it anywhere, so any ideas are welcome.
I want to execute some code on a #WebServlet (javax.servlet.annotation.WebServlet) before it loads my index.jsp. For that I added "/" to the urlPatterns. This does what it's expected in the index.jsp, but it doesn't load my css or image paths any more. The problem is the "/" makes it include all other files in these urlPatterns, but if I try to use "index" instead, it doesn't work.
Can someone please help?
Cheers,
M.
Just use an url-pattern which exactly matches /index.jsp.
#WebServlet(urlPatterns = { "/index.jsp" })
Unrelated to the concrete question, I wonder if you can't better use a ServletContextListener (which is annotable using #WebListener). This is certainly true when your sole functional requirement is to preload/preinitialize some application-wide data on server's startup, regardless of the first-opened webpage.

ASP.NET How to use WebConfigurationManager to get section from Specific config file?

I am trying to get sections from specific .config file such like "my.config".
WebConfigurationManager.OpenWebConfiguration can get the web.config in specific path.
Maybe WebConfigurationManager.OpenMappedWebConfiguration can reach my purpose.
Can anyone share experience?
I don't know about using the OpenMappedWebconfig thing, but this is a way to do it using a easy utility class:
http://aspalliance.com/705
If you want to have neater access to the config, then create a custom class that inherits from ConfigurationSection, then you can access the variables using syntax like MyConfig.configkey, Here's an article that describes how to create the custom class and is good for some further info:
https://web.archive.org/web/20211020133931/https://www.4guysfromrolla.com/articles/032807-1.aspx
This article shows how to do internal custom config sections:
http://www.beansoftware.com/asp.net-tutorials/multiple-config.aspx
HTH,
Lance
EDIT: The aspalliance.com is down, so to tide you over, here are some other helpful links:
Here's a super-simple way to do it - http://www.codeproject.com/KB/files/custom_config_file_reader.aspx
Here's the verbose Microsoft way - http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

Resources