I am beginner in java web-services.
I created a simple web service and when trying to publish it as below
Endpoint.publish("http://localhost:8080/HelloWeb", new HelloWeb());
Getting error as below
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.ravi.jaxws.SayGreeting is not found. Have you run APT to generate them?
at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256)
at com.sun.xml.internal.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:567)
at com.sun.xml.internal.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:514)
at com.sun.xml.internal.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:341)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:227)
at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:308)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:174)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:420)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:439)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:208)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:138)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:90)
at javax.xml.ws.Endpoint.publish(Endpoint.java:170)
at com.ravi.Server.main(Server.java:9)
Any Idea whats going wrong here.
My webservice class is very simple and here is code:
#WebService
#SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL)
public class HelloWeb {
#WebMethod
public String sayHello(String name){
return "Hello "+name;
}
}
first invoke the wsgen utility. This utility generates the various artifacts , i.e. java types needed by the method Endpoint.publish to generate the service's WSDL.Here is the example
In the working directory run
wsgen -keep -cp package.HelloWeb
Related
I'm trying to implement a 2-player network quiz game using RMI. I have a DispatcherInterface (interface) and Dispatcher (implementing the for the former) respecting RMI architecture.
The server model has User and Theme where a Quiz would be in a specific theme, my idea was that when a User connects into a Theme they'd be added into a Map<User,Theme> waitingList until another User comes along to play against them.
My problem lies in the implementation, while trying to implement a simple setter method for adding users to the waiting list I get the following error:
Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: java/sql/SQLException
Which did not make sense to me since my class path is well defined for the RMI registry and the compile/run commands.
public interface DispatcherInterface extends Remote {
public User login(ReceiverInterface client, String email, String password) throws RemoteException;
public void addToWaitingList(int userID, Theme theme) throws RemoteException;
public void addToWaitingList(User user, Theme theme) throws RemoteException;
}
The first method works perfectly with no problems while the other one doesn't regardless of its implementation (tried a simple System.out.print("test")), however I find it inconvenient as I have to loop over the list of connected users in order to get the User instance I need to add to my waitingList. So idealy I am hoping to be able to pass an instance of User to the method.
public class User implements Serializable {
public ReceiverInterface client;
public int id;
public String pseudo;
...
}
I do not understand why I can't pass the a User object to the method, especially since it's serializable.
For completeness sake, for the client part, I have implemented similarly a ReceiverInterface and Receiver that communicate with the server through a proxy (DispatcherInterface)
public class Receiver implements ReceiverInterface {
private DispatcherInterface = proxy;
private User user;
private String serverIP;
public Receiver(String serverIP) throws RemoteException, NotBoundException {
this.serverIP = serverIP;
Registry registry = LocateRegistry.getRegistry(serverIP);
this.proxy = (DispatcherInterface) registry.lookup("QuizApp");
}
...
}
Any help is appreciated.
EDIT:
I use an IDE (IntelliJ) to run my code, it uses the following command:
/usr/lib/jvm/java-10-openjdk/bin/java -javaagent:/opt/intellij-idea-ultimate-edition/lib/idea_rt.jar=41683:/opt/intellij-idea-ultimate-edition/bin -Dfile.encoding=UTF-8 -classpath /home/rand/gm4/JAVA/QuizApp/out/production/QuizApp:/home/rand/gm4/JAVA/QuizApp/lib/miglayout-swing-5.2.jar:/home/rand/gm4/JAVA/QuizApp/lib/miglayout-core-5.2.jar:/home/rand/gm4/JAVA/QuizApp/lib/sqlite-jdbc-3.23.1.jar server.Run
Which is in better terms (without the .jar dependencies), run from the project path is:
javac -d out/production/[project_name] src/server/Run.java
javac -d out/production/[project_name] src/client/Run.java
rmiregistry -J-Djava.class.path=out/production/[project_name]/
java -cp out/production/[project_name] server.Run
java -cp out/production/[project_name] client.Run
You are using jdk 10 to execute your code. In jdk 9 some of the code base was moved into modules and no longer avaliable by default, java.sql is in one of these non root module. You need to use "--add-modules java.sql" with the java command to make the java.sql package avaliable at runtime.
Since you are using intellij to run the code the following doc might help explain how to setup intellij to include this module when run from the ide. https://www.jetbrains.com/help/idea/getting-started-with-java-9-module-system.html
I'm creating a custom ant task, which performs an IO tasks based on the user received param(like an file write/append)
I wanted to write the task so as if the developer using it in the ant task runs it with a -v or -d flag, will output more,
I'm wondering how are the core ant tasks doing it. Are they checking the output level before printing to console or is it just done by using java.util.logging.Logger
Follow this tutorial.
Extract :
Integration with TaskAdapter
Our class has nothing to do with Ant. It extends no superclass and
implements no interface. How does Ant know to integrate? Via name
convention: our class provides a method with signature public void
execute(). This class is wrapped by Ant's
org.apache.tools.ant.TaskAdapter which is a task and uses reflection
for setting a reference to the project and calling the execute()
method.
Setting a reference to the project? Could be interesting. The Project
class gives us some nice abilities: access to Ant's logging facilities
getting and setting properties and much more. So we try to use that
class:
import org.apache.tools.ant.Project;
public class HelloWorld {
private Project project;
public void setProject(Project proj) {
project = proj;
}
public void execute() {
String message = project.getProperty("ant.project.name");
project.log("Here is project '" + message + "'.", Project.MSG_INFO);
} }
[...]
Well, I've created a webservice that i can find accessing locally at:
http://127.0.0.1:8080/myapp/WSPA?wsdl
Now i need to test my webservice by calling it from another java application to verify it its working fine. I've seen that its working using WebService Client from JBoss plugin on eclipse. But the problem is that i have a method wich recieves a list of SoapFile containing a String and array of bytes. And i need to verify if its working.
#XmlType
public class SoapFile implements Serializable {
private String fileName;
private byte[] fileData;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public byte[] getFileData() {
return fileData;
}
public void setFileData(byte[] fileData) {
this.fileData = fileData;
}
}
I've not found how to create a simple webservice client that consumes that service to test.
I would like some direction for this... Tutorial or some website that explains how to make it step by step.
How can i create a java client for this webservice?
Igor, just use wsimport with your web service url - you will get generated classes for WebService and then just invoke service in that way:
ServiceGenerateFromWSImportWhichIsTheSameAsYour iService =
new ServiceGenerateFromWSImportWhichIsTheSameAsYour().
getServiceGenerateFromWSImportWhichIsTheSameAsYourPort();
// now on iServie instance you can invoke method from your webservice
// but you have to use stub classes generated by wsimport
iService.myMethodWhichGetFileList(List<SoapFileStubGeneratedClass> sopaFiles);
And wsimport is standard java tool in jdk instal folder
More on wsimport tool you can find here:
wsimport doc
Using wsimport in your case will be:
wsimport -p generated_classes -s generated_sources http://127.0.0.1:8080/myapp/WSPA?wsdl
and you will find .class files in folder generated_classes and .java files in folder generated-sources
Do you have a WSDL file. If yes then you can use IDE like eclipse to generate client stub.
Below link will also be a good place to start
http://docs.oracle.com/cd/E17802_01/webservices/webservices/reference/tutorials/wsit/doc/Examples_glassfish6.html
A "Hello World" Tutorial with wsimport for Jax-WS can you find here
Tim
I use wsgen to generate Java SOAP stubs.
Using Java basic types or also collections is NO problem.
But if I try to use a custom class as a parameter I get an error from wsgen.
javac I do before over the java-files is without error.
here my Interface.java as an example:
#WebService (targetNamespace = "TNS")
public class Interface
{
public int foo (F f)
{
return 1;
}
}
class F
{
}
The error from wsgen is "cannot find symbol : class F".
I tried also packages, F in own file, etc.
The call of wsgen is: wsgen -cp . -wsdl Interface
any ideas??
thanks!
additional annotatoin solved the problem:
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
found out by looking at the code generated the other way (wsdl -> java) by wsimport.
I try to create web service to Axis2.
I am use eclipse and the "Axis2 Service Archiver" to create aar file from java class.
My problem is that I have function that return custom class like:
public TestClass TestFunc(){
return new TestClass();
}
My question is how my client know what is TestClass? , the TestClass don't show in the wsdl file.
Thanks For the help
If you can see the operation TestFunc() appears in the WSDL - you should be able to see type corresponding to the TestClass in your WSDL. If you cant see, how does the WSDL show the return type of the TestFunc() in the WSDL..?
Thanks..