I was trying to execute a simple Web Service example from a book:
package com.alsb.hello;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import weblogic.jws.WLHttpTransport;
import weblogic.jws.WSDL;
#WebService
#WSDL(exposed=true)
#WLHttpTransport(portName="HelloWorldSoapPort", serviceUri = "HelloWorldService", contextPath = "business/hello")
#SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class HelloWorld {
#WebMethod
public String hello(String arg) {
return arg + "z";
}
}
But when i start the server (Weblogic 10.3.6) it happens the following error:
Errors: The annotation weblogic.jws.WSDL is not allowed on
com.alsb.hello.HelloWorld because it is a JAX-WS type web service.
The same happens with the annotation #WLHttpTransport.
Could someone figure out where's the problem?
"Although this release of WebLogic Server supports both JAX-RPC 1.1 and JAX-WS 2.0 based Web Services, you can use the WebLogic-specific annotations only with JAX-RPC-based Web Services.", check Overview of JWS Annotation Tags from Weblogic. Maybe this could be the reason.
Related
Although I have used EJB earlier, I want to re-assure myself that I understand how it really works.
So, I created a Simple Session Bean EJB (3.1), and packaged it as .ear (which has client jar as well). The below is the snippet:
Session Bean Implementation:
package com.example;
import javax.ejb.Stateless;
#Stateless
public class FirstSessionEJB implements FirstSessionEJBRemote {
public FirstSessionEJB() {
}
#Override
public String print() {
return "Hello";
}
}
Remote interface:
package com.example;
import javax.ejb.Remote;
#Remote
public interface FirstSessionEJBRemote {
public String print();
}
I deployed this EJB as .ear and it was successfully deployed in Wildfly 10.x.
Now, I want to access this using a standalone Java client, running in a separate JVM.
Here is the client code (It might not be completed as I am not clear on how to invoke mainly due to JNDI).
package com.example.main;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.example.FirstSessionEJBRemote;
public class Main {
public static void main(String[] args) throws NamingException {
String GLOBAL_JNDI_NAME="java:global/FirstEJBProjEAR/FirstEJBProj/FirstSessionEJB!com.example.FirstSessionEJBRemote";
Hashtable<String,String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext ic = new InitialContext(jndiProperties);
FirstSessionEJBRemote ejbRemote = null;
ejbRemote = (FirstSessionEJBRemote)ic.lookup(GLOBAL_JNDI_NAME);
ejbRemote.print();
}
}
I referred to this link on how to do the JNDI lookup (and what all parameters to use in, however it is not working.)
In the link it is mentioned that it has Wildfly specific jar which works without JNDI lookup.
Can anyone help me understand:
1) What all properties I need to set up for JNDI look up?
2) Is there any specific jar that needs to be present in client side application?
I don't want to use any specific Wildfly jar, that is, I want to go with traditional JNDI lookup, so can anyone please guide me on this?
It is very frustrating to struggle just to write a simple "Hello world" kind of EJB. I referred to some books are well, but all what they have provided is just the "lookup" code without actually telling what all properties needs to be included for JNDI and any jar to be included.
As the article you link to states albeit a bit hidden in that mountain of text, you do need the jboss-client.jar that you will find in the Wildfly server installation (bin/client/jboss-client.jar); it needs to be on the client's runtime classpath. It contains to begin with that org.jboss.ejb.client.naming package referenced in your code.
The jar contains the extra bit of magic for a client to be able to setup and maintain EJB remote invocations with the Wildfly server, just using JNDI isn't going to cut it. And there is no one jar to rule them all, each container (Wildfly, Glassfish, Weblogic, etc.) has its own implementation for a client library.
Do note that invoking EJBs from a client application is very old school (read: you don't want to do that). A more realistic and modern day view of EJB technology is to use it within an enterprise container itself, such as from a web application / war - say as part of a RESTful service. You likely don't even need the extra layer of the EAR file then, you can just package everything neatly into the one war application.
And in that scenario if you do have a client application, that client can talk to the RESTful service - a much simpler and cross-server, cross-platform communications interface.
I have been given a Java application to maintain and a little confused as to what type of java application it is. The application is quite complex with numerous packages, uses Hibernate and runs on Tomcat.
There is NO servlet class and so no doGet or doPost methods etc and no front end in JSP for example, however it uses javax.servlet.http.HttpSession and in the tomcat\lib folder there is an "servlet-api.jar". Upon looking at the Java classes there is one in particular with web service and web method annotations so is the class with web service end points but there is no "MAIN" method in this class. Also there is a WSDL file in the WebContent\WEB-INF\wsdl location
I have determined that it uses the javax.servlet.http.HttpSession for controlling the session and uses session parameters and some of the imports for the Java class that has the web service annotations are;
import javax.annotation.Resource;
import javax.jws.HandlerChain;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
I have done work with servlets and java web services before but I suppose the question I am asking is - is this a web service application using a servlet api for the HTTP session aspects or is this a Java servlet using JWS components to provide web service end points?
Here is examples of two of the annotations in the relevant Java class;
#WebService(targetNamespace = *manager won't allow me to show anymore of this*
#WebMethod
public String findPrice( ......
This question already has answers here:
Creating a Simple JAX-WS WebService in Eclipse
(2 answers)
Closed 8 years ago.
I am currently working on this tutorial: http://java.dzone.com/articles/jax-ws-hello-world and I'm new to all of this and am looking for some assistance. I get to step 5) where i run the WSPublisher. So I have the project set up in a Dynamic Web Project and when i run the WSPublisher file i use (1) Run on server. Im currently using Apache Tomcat/7.0.53. And i end up getting an HTTP Status 404 - error. Any tips on this 5 minute tutorial would be great as i could easily understand it further.
package juma.mohammad;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public interface Greeting {
#WebMethod String sayHello(String name);
}
..
package juma.mohammad;
import javax.jws.WebService;
#WebService(endpointInterface = "juma.mohammad.Greeting")
public class GreetingImpl implements Greeting {
#Override
public String sayHello(String name) {
return "Hello, Welcom to jax-ws " + name;
}
}
..
package juma;
import javax.xml.ws.Endpoint;
import juma.mohammad.GreetingImpl;
public class WSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());
}
}
This tutorial shows how to host service without server. It's wrong to publish web application on server this way. Server applications doesn't need main method.
In order to run EE application, you need web.xml file.
Follow this tutorial:
http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/ to deploy jax-ws application on Tomcat. Hoever, Tomcat is only Servlet container, so you must provide jax-ws implementation by yourself.
JEE applications should be hosted on EE Servers - like Glassfish, Tomcat EE or Jboss, for name a few. They have EE libraries built in.
Take a look:
http://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html
I'm using Eclipse Juno to create jax-ws webservice on WebSphere® Application Server V8.5 Tools. The WebService sometimes are created but most often he fails to create wsdl. For example, if i try to create a simple webservice named Web:
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService
public class Web {
#WebMethod
public String getName() {
return "myName";
}
}
After deploying this webservice and viewing WebSphere administration page there is no service named WebService. I tried too access the generated WebSphere wsdl from the url localhost:9080/MyProject/WebService/WebService.wsdl but this not exists.
My project have a configured MANIFEST file that contains:
Manifest-Version: 1.0
UseWSFEP61ScanPolicy: true
I'm actually using servlet 3.0 but tried with 2.3. Anyone can help me to do WebSphere approprieate scan annotations of ws-jax and create wsdl on server?
I found a solution when WebSphere not found WebServices. I modify MANIFESTFILE propertie UseWSFEP61ScanPolicy to false, restart the service and modify angain to true, restart the service and he works.
Can I have the same service having simultaneously both REST and SOAP interfaces?
I currently have a REST service implemented in Java using EJB and Jersey:
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Stateless
#Path("test")
public class TestExternalService {
#EJB
private com.test.ejb.db.TestService testService;
#GET
#Path("/status")
#Produces("text/*")
public String status() {
return "ok";
}
}
How can I make changes in my class to also implement a SOAP interface?
Basically, Jersey is JAX-RS implementation, so you cannot have SOAP web-services here. You could take Apache CXF, which is implementation for both JAX-RS and JAX-WS and you would be able to combine your web-services in both architectural styles.
Here is a solution to expose an implementation as both rest and soap web service. Similar to what zack suggested in the comment.
You may have to do some refactoring if you already have the service supporting jax-rs as you pasted above.
The solution is to have two sets of interfaces and implementation. One supporting jax-rs and one jax-ws. You can still have your processing done in the ejb.
Example,
Do not annotate your ejb (say EService) with jax-rs.
Have an interface X and Ximpl class to support restful calls. This will support jax-rs, so basically be annotated with jax-rs. Ofcourse, this can still use jersey. Ximpl will reference the EJB EService and delegate the processing to it.
Have an interface Y and YImpl to support soap based calls. This will support jax-ws, so will be annotated with jax-ws. Yimpl will reference the EJB EService and delegate the processing to it.
If you have a web deployment descriptor, in your web deployment descriptor define different servlets and mapping for rest and soap.