No JaxWS Tutorial works : Java overcomplicated compared to ASP.NET - java

I have read a dozen tutorial on JaxWS and wsgen and none works ! Java really oever complicated for beginners compared to asp.net : in ASP.Net I can make a WS in 5 minutes not in Java : I'm stuck for several days now.
For example I followed this tutorial http://theopentutorials.com/examples/java-ee/jax-ws/create-and-consume-web-service-using-jax-ws/
I'm using Eclipse Luna, JDK 7 and Tomcat 7 and generated stubs and wsdl with wsgen.
I created this Endpoint Publisher class :
import javax.xml.ws.Endpoint;
import com.demo.JaxWS;
public class HelloEndpointPublisher {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://localhost:8080/EclipseJaxWSutotorial/JaxWS", new JaxWS());
}
}
When running it as Java Application why do I get this error and how to fix it ?
Exception in thread "main" java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider com.sun.xml.ws.spi.ProviderImpl could not be instantiated
Update : I do not use maven. I have used wsgen by command line and it generated all classes, wsdl and xsd fine.

Have you check your library dependencies? Check if you have jaxws-rt in your library path. Basically you the maven dependencies will look like this
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.7</version>
</dependency>

Related

" Error Unable to invoke Annotation processoror" wben deploying web service in Weblogic 12c

I have a Webservice implemented with jwsc for Weblogic 12c. It's a WAR file. The classes for the various beans used for the parameters and returns are added with the standard maven plugin, and everything looks OK.
It compiles and packages OK. But any attempt to deploy it gets "Unable to invoke Annotation processoror" (yes, spelt wrong) from the Admin console.
The stacktrace is below, but really doesn't provide much of a hint. I've searched for other questions/answers but have come up blank.
The supporting classes were originally generated with xjc and so had many annotations. I removed those in case that was the issue, but no change. So the only annotations are in the WS implementation class:
#WebService(name = "MyServicePortType", serviceName = "MyService", targetNamespace = "http://test/wsdl/getInfo/v1")
#WLHttpTransport(contextPath = "my-nbi", serviceUri = "/MyService")
#SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL)
public class MyServiceImpl implements OPLService {
There's just a single dependency in the POM:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>wls-api</artifactId>
<version>12.2.1</version>
<type>jar</type>
</dependency>
Possibly connected is that if I try to generate as a JAXWS web service (type="JAXWS" rather than type="JAXRPC" in the args to jwsc) that fails with:
error: Annotation processor 'com.sun.tools.ws.processor.modeler.annotation.WebServiceAp' not found
I've tried adding jars with that class (there are several supplied with weblogic) to the JWSC classpath but with no success (nothing seemed to change at all).
Any ideas on what to try next?
EDIT: One thing I missed was that WL seems to like its SOAP web services as an EAR (containing the WAR). I tried that but still got the error.
I then did what should have done earlier and started with the sample from the documentation (which uses ANT rather than maven, but builds an EAR). That worked, and I've slowly modified that towards the web service I actually need. When I've done, I'll try to work out what the differences are.
<Mar 20, 2022 11:55:57,636 AM UTC> <Error> <J2EE> <BEA-160228> <AppMerge failed to merge your application. If you are running AppMerge on the command-line, merge again with the -verbose option for more details. See the error message(s) below.>
weblogic.utils.compiler.ToolFailureException: Unable to invoke Annotation processoror
at weblogic.application.compiler.FlowDriver.handleStateChangeException(FlowDriver.java:55)
at weblogic.application.compiler.FlowDriver.nextState(FlowDriver.java:38)
at weblogic.application.compiler.AppMerge.runBody(AppMerge.java:168)
at weblogic.utils.compiler.Tool.run(Tool.java:159)
at weblogic.utils.compiler.Tool.run(Tool.java:116)
at weblogic.application.compiler.AppMerge.merge(AppMerge.java:198)
at weblogic.deploy.api.internal.utils.AppMerger.merge(AppMerger.java:94)
at weblogic.deploy.api.internal.utils.AppMerger.getMergedApp(AppMerger.java:58)
at weblogic.deploy.api.model.internal.WebLogicDeployableObjectFactoryImpl.createDeployableObject(WebLogicDeployableObjectFactoryImpl.java:186)
at weblogic.deploy.api.model.internal.WebLogicDeployableObjectFactoryImpl.createLazyDeployableObject(WebLogicDeployableObjectFactoryImpl.java:160)
at weblogic.deploy.api.tools.SessionHelper.inspect(SessionHelper.java:781)
at com.bea.console.actions.app.install.Flow$2.execute(Flow.java:541)
at com.bea.console.utils.DeploymentUtils.runDeploymentAction(DeploymentUtils.java:5787)
[Lots of console related entries removed]
Caused by: java.lang.AssertionError: Unable to invoke Annotation processoror
at weblogic.j2ee.wsee.compiler.WSEEModuleHelper.processAnnotations(WSEEModuleHelper.java:287)
at weblogic.j2ee.wsee.compiler.WSEEModuleHelper.processAnnotationsWithServiceLinks(WSEEModuleHelper.java:245)
at weblogic.j2ee.wsee.compiler.WSEEModuleHelper.processAnnotations(WSEEModuleHelper.java:178)
at weblogic.wsee.tools.WSEEWebAppToolsModuleExtension.processAnnotations(WSEEWebAppToolsModuleExtension.java:216)
at weblogic.wsee.tools.WSEEWebAppToolsModuleExtension.merge(WSEEWebAppToolsModuleExtension.java:109)
at weblogic.application.compiler.flow.SingleModuleMergeFlow.proecessModule(SingleModuleMergeFlow.java:33)
at weblogic.application.compiler.flow.SingleModuleFlow.compile(SingleModuleFlow.java:64)
at weblogic.application.compiler.FlowDriver$FlowStateChange.next(FlowDriver.java:70)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.compiler.FlowDriver.nextState(FlowDriver.java:37)
at weblogic.application.compiler.BaseMerger.merge(BaseMerger.java:20)
at weblogic.application.compiler.flow.AppMergerFlow.mergeInput(AppMergerFlow.java:75)
at weblogic.application.compiler.flow.AppMergerFlow.compile(AppMergerFlow.java:40)
at weblogic.application.compiler.FlowDriver$FlowStateChange.next(FlowDriver.java:70)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
at weblogic.application.compiler.FlowDriver.nextState(FlowDriver.java:37)
... 116 more

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Serializable while using ActorSystem in Java project

I am new to java and AKKA toolkit. I have created a JAVA project and tried to include the below code
package com.postgresqltutorial;
import akka.actor.ActorSystem;
public class App {
public static void main(String[] args) {
final ActorSystem system = ActorSystem.create("QuickStart");
}
}
I have used AKKA libs in referenced libs as akka-actor_2.12-2.6.15.jar, akka-protobuf_2.12-2.6.15.jar and akka-stream_2.12-2.6.15.jar.
And my project structure is like
project structure
Please help me to resolve this.
Most likely you've not referenced the libraries correctly. That is why you should use a build tool such as Maven. Check the referenced link to understand how it works. It handles the libraries for you, you just have to add them in the pom.xml file.
Example:
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_3</artifactId>
<version>2.6.18</version>
</dependency>
</dependencies>

javax.jcr.RepositoryException trying to follow Adobe example

I'm trying to follow this example from Adobe:
How to programmatically access the AEM JCR
My code looks like this:
package com.example;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import org.apache.jackrabbit.commons.JcrUtils;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
try {
//Create a connection to the CQ repository running on local host
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
} catch (Exception ex){
System.out.println(ex.toString());
ex.printStackTrace();
}
}
}
My pom.xml has these dependencies:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<version>2.21.7</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
<version>2.21.7</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr2dav</artifactId>
<version>2.21.7</version>
</dependency>
</dependencies>
When I run with this command:
`java -jar .\target\demo-jar-with-dependencies.jar`
I get the following output:
javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
Perhaps the repository you are trying to access is not available at the moment.
javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:224)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:264)
at com.example.App.main(App.java:20)
I've found a number of articles both here and on other sites but none of the suggestions I've found have done anything to resolve the issue.
Any thoughts on what I'm doing wrong? I'm pretty new to AEM. Yes, the AEM Author server is running and it's on port 4502. In fact if I open this URL in a web browser I get:
Which seems normal.
Update: The consensus seems to be that I'm going about this incorrectly by using Maven and not downloading the Jackrabbit Standalone library from Apache. So I created an entirely new project in Eclipse, without Maven, and added jackrabbit-standalone.jar Version 2.23.0 (which is the latest) as a reference library. The result is exactly the same:
I've setup a Github repository for this code at:
Github Repo
Please feel free to clone it and see what I'm doing wrong.
We usually write our AEM code in OSGi bundles that we deploy in AEM. If you want to use the JCR API to connect to an AEM instance follow the advice here:
To use the JCR API, add the jackrabbit-standalone-2.4.0.jar file to
your Java application’s classpath. You can obtain this JAR file from
the Java JCR API web page at
https://jackrabbit.apache.org/jcr/jcr-api.html.
Once you download that file you have two options:
1/ No Maven - compile your program manually using javac -classpath ... (and specify the jackrabbit-standalone JAR in the classpath), and run it using java -cp ...
2/ With Maven - install the JAR in the Maven repo (or add it as a dependency using <scope>system<scope>, but you also have to run your program using Maven
Note that the Maven dependencies do not affect the program, the jackrabbit-standalone JAR is all you need to run the code you wrote.
So you're trying to access AEM using Jackrabbit WebDV.
It's pretty clear that you don't have the right components in the class path. You likely need all "spi" related components (these can the WebDAV-related client code), plus "jackrabbit-jcr-commons".
You definitively do not need core; as that would a for a local repository instance.

Tomcat 8 and Websocket

i've troubles getting my application to tomcat 8. I'm using websocket and spring 4 but i don't want to use the spring internal STOMP mechanism so i've decided to follow this tutorial and implemented my websocket routines my way.
I'm developing since a couple of weeks now and tested it always with jetty (maven jetty plugin) and everything works fine. But now i want to deploy my application to our production server running tomcat 8.0.15 on java 8 and CentOS but it's not working.
Here is the sourcecode:
#WebListener
public class MyApplication implements ServletContextListener {
private final static String SERVER_CONTAINER_ATTRIBUTE = "javax.websocket.server.ServerContainer";
#Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext container = sce.getServletContext();
final ServerContainer serverContainer = (ServerContainer) container.getAttribute(SERVER_CONTAINER_ATTRIBUTE);
try {
serverContainer.addEndpoint(new MyEndpointConfig(MyEndpoint.class, "/wstest"));
} catch (DeploymentException e) {
e.printStackTrace();
}
}
}
And here's the error:
java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to javax.websocket.server.ServerContainer
at my.package.contextInitialized(MyApplication.java:23)
Line 23 is where i do the cast to ServerContainer.
I guess that "container.getAttribute(SERVER_CONTAINER_ATTRIBUTE)" returns null and therefore the cast fails, but why??
It's all working fine with Jetty 9.2.3. I've tested it also with a local tomcat 8 installed (newest 8.0.18) and the latest JDK 8 on Windows 7 and same behaviour.
Do you have any ideas how to fix this?
Thank you very very much!
Appleman1234 is pointing to a very useful bug report. See Iyad Elian comment:
FYI, I found why the exception happens javax.websocket-api like javax.servlet-api needs to be excluded at runtime in tomcat. jetty prefers application classloader to it's own however so it's not a problem.
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
And that's exactly why it was not working on tomcat but on jetty. I've just added
<scope>provided</scope>
and now it's working fine. Thanks to Appleman1234!

JAXWS code generation and implementation along side Spring for JDK1.5

We're trying to generate source code stubs from a series of WSDLs (each with their own XSDs). We can do this fine and works perfectly under JDK1.6, however we need it to work under JDK1.5.
We're using jaxws-maven-plugin to generate the source code, however it depends on the wsimport binary being available (this is not available in JDK1.5). We found a work around for this, we can now generate the source code.
The final problem comes when we try and use the compiled stub code with Spring (2.5.6) we're using a JaxWsPortProxyFactoryBean to interface with the generated client code. We get a java.lang.NoClassDefFoundError: javax/xml/ws/soap/Addressing. I investigated why this was and found that the javax.xml.ws/javax-api/2.1 dependency did not contain this class. I upgraded the version number to 2.1-1 and now when we build the project (to generate the source code) we get the following error:
cannot find symbol
symbol : method partName()
location : #interface javax.jws.WebParam
Can anyone provide a solution to this so we can generate our JAXWS client stub code and make it work with the JaxWsPortProxyFactoryBean?
Thanks in advance
Jonathan
It seems that they mess with this jar, see this link.
The workaround is the following :
delete M2_REPO/javax/xml/ws/jaxws-api/2.1/ directory
use this dependency
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1</version>
</dependency>
put these repositories at the top of your list :
<repository>
<id>javanet</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>javanet legacy</id>
<url>http://download.java.net/maven/1/</url>
<layout>legacy</layout>
</repository>
I managed to solve this one, after hours of studying the dependencies and looking at what each of them had inside I discovered that the dependency javax.xml.ws:jaxws-api:2.1-1 was required, but we had to take a copy of this dependency and take out:
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181</artifactId>
<version>1.0</version>
</dependency>
Then I had to include the following dependency in the pom.xml of my application:
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0-MR1</version>
</dependency>
This is far from ideal, we have to maintain a separate proprietary dependency in our maven repository and remember to include this dependency. The annoying thing is Maven doesn't allow me to exclude by version number (only by groupId and artifactId). If anyone has a suggestion to make this solution better please let me know.
Thanks for your help.
We're using jaxws-maven-plugin to generate the source code, however it depends on the wsimport binary being available (this is not available in JDK1.5). We found a work around for this, we can now generate the source code.
Actually, wsimport, which is part of JAX-WS, is not included in Java 5 (unlike Java 6 which includes JAX-WS 2.x, Java 6u14 includes JAX-WS 2.1.6) but it is available for Java 5 as long as you provide it. The odd part is that the jaxws-maven-plugin declare these dependencies (see for example jaxws-maven-plugin-1.12.pom), there must be a classloading issue somewhere, hence the "work around".
The final problem comes when we try and use the compiled stub code with Spring (2.5.6) we're using a JaxWsPortProxyFactoryBean to interface with the generated client code. We get a java.lang.NoClassDefFoundError: javax/xml/ws/soap/Addressing. [...]
What version of the plugin are you using exactly? I'd suggest to use the version 1.12 and the same version of jax-ws as in the plugin in your pom.xml:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>

Categories

Resources