WSImports specify package name for a class - java

I have following scenario, I have two packages say com.ws.a and com.ws.b.
Both the packages having web-services classes. com.ws.a contain class TestServoceA which is having method which returns class TestA.
I want to pass this generated class to TestServiceB which is in com.ws.b.
But wsimport tool generate two different classes for both packages like:
com.ws.a.TestA and
com.ws.b.TestA
I want to generate only one class com.ws.a.TestA as a proxy and use it in both namespaces.
How can I do this? If custom binding can help me please give me example.
Thanks.

wsimport will use JAXB for data binding, follow this documentation to specify custom bindings:
http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html

Related

Bazel build with Jackson annotations for ser/Deser and generate Java classes

So, we have been trying to xploring bazel as a build system for our organization, since we have a huge monorepo.
One of the problems I'm facing is, we have some code-gen classes which use Jackson's annotation processors to generate immutable copies of some file types.
Eg :
#JsonSerialze
#JsonInclude(JsonInclude.Include.NON_EMPTY)
#Value.Immutable
#JsonDeserialize(as=ImmutableABC.class)
Public abstract class ABC {
...
}
So, for this , I include a java_plugin tag in bazel build file for this module as follows :
Java_plugin(
name="abcgen",
srcs=["src/.../ABC.java"],
Deps=[ {jackson-deps go here}],
processor_class = "org.immutables.processor.ProxyProcessor",
)
This always fails , saying cannot find the ImmutableABC.class file which is referenced in the annotation.
Any ideas? Am I missing the processor class for the Jackson annotations, and also is it possible to include multiple processor classes?
For anyone facing issues as such, ensure generates_api = 1 for your plugin, if the generated classes are used in the library, as for the jackson part, that wasn't really the problem

Load dynamic library java that inherit interface

I want to load dynamic library where classes inherit from an interface/abstract class on my core project, so I can load my classes at runtime and use it. How can i do that ?
Example:
Core: ITrigger (interface)
Library: {MyTriggerOne extends ITrigger} {MyTriggerTwo extends ITrigger}
If you want to load a class/library dynamically use Class.forName('class name') method to load.
I had the same requirement and I used the library Reflections.
Very simple code snippet:
public Set<Class<? extends ITrigger>> getITriggerClasses() {
final Reflections reflections = new Reflections("package.where.to.find.implementations");
return reflections.getSubTypesOf(ITrigger.class);
}
Then you can use the method Class::newInstance to create the ITrigger(s).
This is a very simple example, there are several options to initialize the Reflections class (not only with one package name).
Java's SPI(Service Provider Interface) libraries allow you to load classes dynamically based on the interfaces they implement, that can be done with the help of META-INF/services.
You can create a interface like
package com.test.dynamic;
public interface ITrigger {
String getData();
String setData();
}
you can use the ServiceLoader class to load the interface like below code
ServiceLoader<ITrigger> loader = ServiceLoader.load(ITrigger.class);
then you can perform all the operation on it.
If you have some other implementing classes on your classpath, they register themselves in META-INF/services.
you need to create a file in META-INF/services in your classpath with the following properties
The name of the file is the fully qualified class name of the
interface, in this case, it's com.test.dynamic.ITrigger
The file contains a newline-separated list of implementations, so
for the example implementation, it would contain one line:
com.test.dynamic.impl.SomeITriggerImplementation class.

JMeter Beanshell share class definitions

is there a way to share class definitions between scripts created purely in jmeter? For instance if I had the following structure:
Thread1
-BSSampler
-BSSample2
How can I create a class in BSSampler and use that same class definition in BSSample2 explicitly? Or would I have to push the class definition out to a file and use
${__beanShell(source("filename.bsh"))}
to share the same class definitions? Right now it's saying it doesn't recognize the class definition because it's a different namespace.
You can declare your classes and functions in a bsh file that you reference in user.properties through:
beanshell.server.file=../extras/startup.bsh
You can have a look at this file in extras/startup.bsh

Passing a customized object to Scala template

I have an object profileModel in my profile package and my profile.scala.html file have following code
#(model: ProfileModel)
when I compiles, it is giving an error recursive value model needs type
But when I moved this class to models with my application.conf as
ebean.default="models.*"
it works.
My guess is scala compiler automatically adds models.* to class path at the time of compilation
Is there a way to make this work without moving the class back to models package ?
I am using play 2.2.1 built with Scala 2.10.2
If I understand you right, if your ProfileModel exists in profile package correct declaration in the view should be:
#(myProfile: profile.ProfileModel)
And 'yes', Play imports automatically all models and controllers (and also other well known types), but if you want to use any type in custom package (or ie. imported lib) you need to use full qualified path to it.

Registering XmlAdapter globally for any classes in different packages

I'm using CXF 2.4 with JAXB.
Could I have a global XmlAdapter for all instances of my owm class (e.g. LWDate)?
I wrote a class:
public class LWDateAdapter extends XmlAdapter<Date, LWDate>
Right now I have to add #XmlJavaTypeAdapter on each param, method or package that I plan to use with CXF. E.g.
#WebMethod void test (#WebParam(name="Birthdate") #XmlJavaTypeAdapter(LWDateAdapter.class) LWDate pBirthdate){}
I wish to ask CXF/JAXB always bind my class LWDate to java.util.Date is it possible?
UPDATE: #XmlJavaTypeAdapter works on a package level staring from version 2.4.4 according to that issue.
For your use case using the #XmlJavaTypeAdapter annotation at the package level is your best option. Below is a post where I use this strategy for the Joda-Time classes:
http://blog.bdoughan.com/2011/05/jaxb-and-joda-time-dates-and-times.html
If you have a domain class that you always want to be handled with an XmlAdapter you can use the #XmlJavaTypeAdapter annotation at the type level:
http://blog.bdoughan.com/2010/12/jaxb-and-immutable-objects.html

Categories

Resources