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
Related
Stack
Java
Jakarta EE 10
JBoss/Widlfly 27
Kubernetes K8S
JAX-RS (RestEasy)
I want to initialize some caches on startup of my app. During that time i want my readiness probe to respond not ready.
With the management inteface turned on, this works BUT not with my classes, instead the standard one responds.
Wildfly runs in standalone mode.
What i try to accomplish is to run my OWN code for readiness/live BUT that these endpoints are available during startup. I created my own outside of microprofile.healt but they are not available during startup.
Does anybody have some ideas?
Below is my code
import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;
/**
* Created by Gerry Askefalk on: 2023-01-13
*/
#ApplicationScoped
#Liveness
#Readiness
public class Mycheck implements HealthCheck {
#Override
public HealthCheckResponse call() {
return HealthCheckResponse.named("mycheck").up().build();
}
}
Ok
the solution (and my bad) was to not add microprofile extensions to WF.
When i did, it works!
This article explained it to me.
microprofile on wf
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 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.
I am learning EJB and I am trying to execute the Helloworld example given in EJB In Action book.
My app server is JBoss, I created the Jar file for the bean class and interface in the right directory( I can see the EJB in JMX console).
Now I created a simple client using EJB annotations, but I am getting a NullPointerException.
Here is my client code.
Client code:
package com.client;
import javax.ejb.EJB;
import com.EJB.*;
public class HelloWorldClient {
#EJB
private static HelloWorldInterface HelloBean;
public static void main(String[] args)
{
HelloBean.SayHelloWorldInEJB();
}
}
Bean class
package com.EJB;
import javax.ejb.Stateless;
#Stateless
public class HelloWorldBean implements HelloWorldInterface {
public void SayHelloWorldInEJB() {
// TODO Auto-generated method stub
System.out.println("Hello world from the world of EJB");
}
}
Interface
package com.EJB;
import javax.ejb.Local;;
#Local
public interface HelloWorldInterface {
public void SayHelloWorldInEJB();
}
Note: I tried using specifying the interface as Remote, it still didn't work.
Steps that I did so far to get to this point.
1) Created the file EJB files
2) Made the build.xml and deployed the EJB.
Am I missing any configuration files ???
Now I created a simple client using EJB annotations, but I am getting a NullPointerException.
Your client code looks like an Application Client and such client is supposed to be deployed on the app server and then executed in an Application Client Container (ACC) so that injection can occur. Starting the ACC requires an application server specific command.
The following wiki explains the usage of the ACC in JBoss (how to package, deploy and launch an ACC): How to use an application client in JBoss-5.
If you don't want to use an Application Client Container and instead just run the application client class through a java command, injection won't be possible and you'll have to perform a JNDI lookup.
And in both cases, you'll have to provide and use a remote business interface for your bean.
Resources
How to use an application client in JBoss-5
Creating and Running an Application Client on the GlassFish Server
Related questions
application-client
You would have to make two changes:
Replace the #EJB dependency injection with JNDI lookup. Dependency Injection is not supported for POJOs in EJB 3 (Don't know about EJB 3.1 though )
Then, the interface has to be a remote interface. The reason is that, the client here is a standalone java program - It would be running in JVM different from the web-app JVM.
Both dependency injection through #EJB and having the interface as #Local should work if the client was a servlet in the same server.
I want to build simple SOAP web service. So far I've only worked with existing SOAP/Rest services. And now I'd like to create my own, simple one for starters.
For example create simple hello + string web service where I provide the string in request from SOAP ui or similar tool.
I have Jboss server installed already, what is the "simplest" possible way to achieve this? I realize I need interface, interfaceImpl, and a wsdl file(generated possibly).
Does anyone have some useful advice for me ? thank you
If you want something extremely straight forward, use JAX-WS and a Java first approach. Here is what a Hello world web service looks like:
#WebService
public class HelloWebService {
public String sayHello(String name) {
return "Hi" + name;
}
public static void main(String ... args) {
HelloWebService hello = new HelloWebService();
Endpoint endpoint = Endpoint.publish("http://localhost:8081/hello", hello);
}
}
Java 6 includes JAX-WS RI, an implementation of JAX-WS, so you can run this code as is and test it with SAOP-UI (the generated WSDL is available at http://localhost:8081/hello?WSDL).
JBoss supports JAX-WS through a native stack - but you can also use Apache CXF or Metro (Metro = JAX-WS RI + WSIT). Check JBossWS for more details. I suggest to start with their native stack.
See also
Getting Started with JAX-WS Web Services
Building Web Services with JAX-WS in the Java EE 6 Tutorial