Java JAX-WS, wsgen, Class as Parameter? - java

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.

Related

clojure gen-class with annotation that require enum parameter

I want to write a clojure lib and exposes generated classes, so that other java projects could use it.
I read and followed the gen-class doc, and everything works as my expect, except class annotation with enum parameters.
(ns common.exception.unauthorized
(:gen-class :name
^{org.springframework.web.bind.annotation.ResponseStatus
org.springframework.http.HttpStatus/UNAUTHORIZED} ; <- here
com.lalala.common.exception.Unauthorized
:extends java.lang.RuntimeException
:init init
:constructors {[String] [String]}
:main false
:prefix "unauthorized-"))
(defn unauthorized-init [^String message]
[[message] nil])
This exception class is generated without any error, and it also able be used as an Exception. However, this exception is intended to be used as a http response along with spring web. The spring framework read the annotation, and find that it is HttpStatus/UNAUTHORIZED then response 401. But the spring framework throws exception complaining that java.lang.EnumConstantNotPresentException: org.springframework.http.HttpStatus.
And I had a look at the generated class, it's something like this:
#ResponseStatus(HttpStatus.401)
public class Unauthorized extends RuntimeException {
private static final Var init__var = Var.internPrivate("common.exception.unauthorized", "unauthorized-init");
private static final Var getStackTrace__var = Var.internPrivate("common.exception.unauthorized", "unauthorized-getStackTrace");
// ...... ellipsis
}
As it shown, the HttpStatus/UNAUTHORIZED is compiled into HttpStatus.401 which is invalid.
I also tried with {:code org.springframework.http.HttpStatus/UNAUTHORIZED}, {:value org.springframework.http.HttpStatus/UNAUTHORIZED}, it can be compiled into #ResponseStatus(code/value = HttpStatus.401), but the enum value itself still in invalid form HttpStatus.401.
Am I use class annotation for gen-class in a wrong way? or just Clojure compiler just have this bug?
P.S. tried with Clojure 1.9, 1.10, 1.10.1
Finally, I use native Java code instead. I realized that writing classes in clojure with only ctor forwarded to super class is making trouble for myself.
I embedded java code in the project along with :java-source-paths configured in defproject, got my problem solved.

How to execute scala code using java

I am new to scala. I have a requirement to execute the scala class using java.
My exact requirement is: I need to pass the entire scala class (file) as an argument to the java jar. That jar should read the scala code and execute it. I have searched many sites but did not find the appropriate answer. Is there any way to do the same?
Thank you in Advance.
Besides of your motivation to do that, it is for sure possible (I did it using my IDE - sbt project)
I just made scala class as below:
import com.google.common.base.Objects
class Car(_color: String, _valid: Boolean) {
val color: String = _color
val valid: Boolean = _valid
override def toString = Objects.toStringHelper(this).add("color",color).add("valid", valid).toString
}
After that I made class with main method to test it.
public class Test {
public static void main(String[] args) {
Car test = new Car("test", true);
System.out.println("test = " + test);
}
}
It compiled without any problems and the result was like below:
test = Car{color=test, valid=true}
Scala has its own compiler scalac whereas java uses javac. Since scalac compiles to class file that java can read and assuming that you are only using java libraries in the class then you can load the class in java. So what you need is to call scalac to compile the scala file and then load the generate class file using ClassLoader

Trouble with generating custom javadoc; 'cannot find doclet'

I'm having a go at creating a custom Javadoc generator using Doclet, but I'm running into some issues.
I'm following the official documentation and initially had trouble with including the tools.jar file in my project, but I managed to fix this.
My issue now is that after running this command...
javadoc -doclet ListClass -docletpath . MyClass.java
...I am getting the message...
javadoc: error - Cannot find doclet class ListClass
As I said, I've mostly been following the tutorials from the official documentation, but here is my code for reference.
ListClass.java:
import com.sun.javadoc.*;
public class ListClass {
public static boolean start(RootDoc root) {
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; ++i) {
System.out.println(classes[i]);
}
return true;
}
}
And MyClass.java:
/**
* Documentation for my class
*/
public class MyClass {
public static void main(String[] args) {
}
/**
* Documentation for my static void method
*
* #param param This is the parameter it takes in
*/
public static void myStaticVoidMethod(String param) {
}
}
So what I am asking is why I am getting the error I posted above. If someone was able to provide a more comprehensive guide of how Doclet works that would be great as well.
Note: I'm using IntelliJ IDE for my project. Here is my directory structure:
.idea
...
out
...
src
ListClass.java
MyClass.java
JavadocGenerator.iml
You need to compile your ListClass file. Something like:
javac -d . ListClass.java -cp /path/to/tools.jar
Doclet classes are part of the tools jar, so you'll need to include it as your compile-time dependency.
Then your command
javadoc -doclet ListClass -docletpath . MyClass.java
should work.
edit
For you project structure, if you're compiling from the root directory, make sure to reference your files through their subdirectories, and make sure any absolute windows paths are double-quoted:
javac -d . ./src/ListClass.java -cp "C:/Program Files/Java/jdk1.8.0_66/lib/tools.jar"
This would create a compiled ListClass file at the root of the project, and from there use your javadoc command:
javadoc -doclet ListClass -docletpath . ./src/MyClass.java
It would be better to create a classes directory to place your compiled classes, as opposed to in the root of the project, but I'm just working with the structure you've provided. See the documentation for javac and javadoc for more info.

runtime modeler error while creating very simple web service in java

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

MWE2 Workflow component with Scala language

I'm trying to write a MWE2 workflow component using scala language.
Below is the scala code:
package com.ford.modelling.workflow
import org.eclipse.emf.mwe2.runtime.workflow.{IWorkflowComponent, IWorkflowContext}
class SayHello extends IWorkflowComponent {
var message : String = null;
def preInvoke {}
def invoke(ctx : IWorkflowContext) { System.out.println(message) }
def postInvoke {}
}
and below is the workflow code:
module com.ford.modelling.workflow.SomeWorklow
SayHello {}
I can't figure out why does this workflow complain for error:
'com.ford.modelling.workflow.SayHello' does not have a public default constructor.
I'd assume that the scala IDE plugin does not mimic the java protocol completely, e.g. the IType does not expose a no-args constructor. You may want to ask the scale folks about it.
The error message should vanish as soon as you add a default constructor explicitly. Does that make sense?
A quick google search indicated that there probably no syntax for a default constructor so I'd assume it's a scala tooling problem. Does the problem occur at runtime, too?

Categories