Grizzly - java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName - java

I have a wsdl file for the Web service. I want to test the interaction between the client and the server. To do this, I run the mock server with embedded grizzly.
The question about of implementing mock server. I generated an interface from wsdl (and xsd) using the wsimport and wrote implementation. When run on the grizzly, I get the following error:
com.sun.xml.ws.server.ServerRtException: [failed to localize] cannot.load.wsdl(META-INF/wsdl/test.wsdl)
I run a web service with this code:
HttpHandler httpHandler = new JaxwsHandler(new TestImpl());
server.getServerConfiguration().addHttpHandler(httpHandler, "/test");
The problem is that Grizzly can not find wsdl and xsd files. In embedded glassfish its work.
EDIT1
I change wsdlLocation to "test.wsdl" and its work. But now grizzly say:
java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;
EDIT2
If use JDK1.7 it works. But I need a JDK 1.6

I'm not sure why you're seeing that error. I can run the Grizzly jaxws example and obtain the wsdl using either 1.6 or 1.7.
I would recommend reviewing the source1 of the example and compare to what you have.

I'm change the jdk6 to jdk7 and works fine! Don't forget to change the JAVA_HOME and the default JDK of Netbeans as related here: How to set the JDK Netbeans runs on?

Your version of Grizzly expects a JAX-WS 2.2 API while JDK 1.6 ships with JAX-WS 2.1. As others mentioned, some of these files need to be installed into an endorsed directory. You can download the required files here or take them from your Grizzly installation. The download includes an Ant build file that provides a build target to install the files into the JDK endorsed directory. You can run it with ant install-api. If you cannot run Ant, you may install them manually:
cp lib/jaxb-api.jar $JAVA_HOME/lib/endorsed
cp lib/jaxws-api.jar $JAVA_HOME/lib/endorsed
Do not install other files from the JAX-WS distribution into the endorsed directory unless you want to create some really difficult to debug bugs for yourself.
I am suggesting to use the endorsed directory in $JAVA_HOME/lib/endorsed because that will work with most tools and applications without any additional changes. Others already suggested more targeted changes, such as setting an endorsed directory during a Maven build or copying the files into a Tomcat endorsed directory. All these approaches are fine as long as you can make sure that your code is picking up the right endorsed directory.

As a result, we had to use endorsed mechanism. Documentation

create a folder called endorsed and put these jar files in it
1.jaxb-api-2.2.jar
2.jaxws-api.jar
put the folder in tomcat server as
C:\tomcat-7.50\< created folder>
and run it will works

Changing JDK from 1.6 to 1.7 worked for me.

Related

How does WTP determine the Tomcat version

I found in Why won't the New Server Runtime dialog recognize my Linux installed version of Tomcat? that:
When identifying Tomcat 5.0.x, a servlet-api.jar is expected to be
present in the common/lib directory.
but my problem is I have a slightly modified Tomcat 7.0.30 and WTP thinks it's 5.1
Where can I find a list of actual checks per Tomcat version?
Looks like the anwser is here: https://github.com/eclipse/webtools.servertools/blob/master/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatVersionHelper.java
Funny thing, they don't inspect the external file CATALINA_BASE/lib/org/apache/catalina/util/ServerInfo.properties as described in https://tomcat.apache.org/tomcat-7.0-doc/security-howto.html

JMS client tool - any alternative to HermesJMS for Java 8?

What alternatives to HermesJMS are available? I need to test against JBoss WildFly 8 and it uses Java 8. HermesJms seems to be built for Java 6 and I could not find a full Java 8 port for it. I tried setting hermes.bat with this configuration option but I get the following error:
org.xml.sax.SAXNotRecognizedException: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.
This seems to be due to Xerces JAR version but I am worried if all other libs under %HERMES_HOME%\lib\ext will have similar Java 8 compatibility issues. Best way is to use a Java 8 compatible build of HermesJMS rather than try fixing JARs one by one but that seems not possible given that there is no such branch.
Thanks,
Paddy
To let it work for Java 8 correctly, you need to add the following parameters:
-Dorg.xml.sax.parser=com.sun.org.apache.xerces.internal.parsers.SAXParser -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
Windows
Open bin/hermes.bat and add those parameters after start "HermesJMS" "%JAVA_HOME%\bin\javaw".
Linux / Mac
Open bin/hermes.sh and add those parameters in the last line after "$JAVACMD".
This seems to be related to java 7 vs 8 difference in XMLP
To make it work I updated Hermes lib folder with :
xercesImpl.jar (version 2.11) - I can see latest in SP5 now
xml-apis.jar (1.4.01)
After downloading JARs from MVN repo I renamed to match existing naming in Hermes.
After this change Hermes starts (and works fine when using JMS) and there is no error in logs.
You could give a try to JMSToolBox (on sourceforge)
Remove xerces.jar and xercesImpl.jar from the %HERMES_HOME%\lib directory. With these parsers removed from the lib, Hermes will default to the SAX parser in JDK8 and will work better.
Click here for additional detail.
It worked for me by adding the following jar file to lib directory.
xercesImpl

Changing Java manifest.mf file and deployment to server

I'm developing an application that should run on a server. The application uses some external jars.
I have build the application and run it on a local machine without a problem.
Now, I need to deploy it on the server. The server has some of the jars located.
What should I do to make my application work on the server, using the jars that are already there?
I don't have much experience with Java, but I understand that there is a manifest file which has a class-path field that points to all the jars needed. Should I change the manifest "manually", so that it points to the location of the jar on the server? What do you do in situations like this, what is the correct procedure?
Also, if I use one version of jar during development, and there is a bit older version of that jar on the server, what should I do to perform the deployment correctly?
And what is the procedure in case of using maven, should I copy the jars from where it locates them on the local drive to one directory, or is there a way for maven to do it itself?
I'm using NetBeans btw.
Thanks
Re "using the jars that are already there":
See Introduction to the Dependency Mechanism, Dependency Scope: "provided ... indicates you expect the JDK or a container to provide the dependency at runtime."
Re "there is a bit older version of that jar on the server":
Update the library on the server or use the older when developing. I'd consider it a really bad idea to use different versions of a library for developing and runtime. This can lead to subtle errors that are hard to identify.
Re "And what is the procedure in case of using maven":
Does the introduction linked above help you in answering this as well?
Maven is supposed to work the same with any type of IDE.

JAX-WS 2.2 and JDK6 with maven

I have a web service and I'm using the Endpoint.publish("http://0.0.0.0:8080")
Thing is that JAX-WS 2.0 and 2.1 is affected by an issue that throw a NullPointerException when executing endpoint.stop().
The issue is fixed in 2.2 but when adding the dependency in the pom.xml publishing fails due to a java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String; since I'm using java 1.6.
The workaround is to add to the endorsed folder some libs. But I want to pack it all in jar-with-dependencies. An executable java jar.
Said this, I would be thankful if you help me:
Publishing the endpoint in 2.0 or 2.1 listening to all addresses (0.0.0.0)
or
Configuring dependencies in maven to pack everything using 2.2.x
but executable with JDK6
EDIT:
Requirements are a deliverable jar. A single jar that pack all of the dependencies (2 so far, about a 400k jar).
But if you think that the only way to make it work is to add an external shell script please let me know too.
Thank you!
The executable jar format does not allow for endorsed folders required for JAX-WS replacement (and neither does the Java WebStart launcher apparently).
You need to use something that can construct and execute a new "java" command on the fly. The best way from here is most likely to look for an installer which can run the program directly without needing to install.
What exactly do you need to happen?
EDIT: As the requirement is a runnable jar you simply cannot do this with JAX-WS 2.2 Find a workaround with the JAX-WS present in the latest release of the Java version you are targetting.
It is very nice that the JAX-WS stack ship with core Java allowign for very small deployments, but a pain that you cannot easily provide your own.
Note that you can provide your own with Java 5 but then you need to bring your own Endpoint implementation.
Do you need to use the JAX-WS RI? You could use CXF instead which is a fine JAX-WS implementation and doesn't suffer the same collision problems as the RI.
Edit: You could try to generate the classes with the RI, but use CXF in the deployment. JAX-WS is a spec after all so it should work...

Missing javax.servlet.http.Cookie class

I haven't been using Java extensively hence forget a lot fundamental things. Basically, I am working with a web-dynamic project (using Eclipse IDE with jdk 1.6), and during the build, I get errors that Cookie class and other web related classes cannot be found. What am I missing?
What Jars files do I need to add (and how)?
thanks
Think you need servlet-api.jar
Try here for any jar files you need http://www.java2s.com/Code/Jar/CatalogJar.htm
Sounds like you are missing servlet-api.jar
You can download it from the Maven repository.
Servlets are only part of the Enterprise Edition, not of the Standard Edition of Java. So you need the Java Enterprise Edition, AKA Java EE.
http://java.sun.com/javaee/
As others have said, you're missing the server api jar.
Having said that, downloading just the servlet api jar and not the server that goes with it means that you can't actually test your code.
In Eclipse, once you're installed a servlet container, such as Sun's Glassfish, Apache Tomcat, or Jetty, you can create a server instance of it so that Eclipse will compile against your server's servlet implementation. Creating a server instance also means that Eclipse's Run on Server command works.
IBM has a slightly outdated guide on Developing Web applications with Tomcat and Eclipse. The entire "Install the Web tools" section can be skipped if you have the Eclipse EE version, as Web Tools are already installed.

Categories

Resources