Axis2 Faulty Pojo Web Service - web-services

I have created a pojo as below.
package demo;
public class HelloWorld {
public String sayHello(String name) {
return "Hello " + name;
}
}
I placed it in axis2 war and opened
http://localhost:8080/axis2/services/listServices.
Axis 2 is indicating it as faulty service
Faulty Services
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\demo\HelloWorld.class
But when I remove package declaration statement and place it on below location, everything works fine
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\HelloWorld.class
Now there are two possibilities
Package declaration is not allowed in pojo (and I don't believe this).
I am missing something.
Can anyone guide me?

In the book "Apache Axis Web Services, 2nd Edition", author described that when exposing a pojo class as a web service by dropping in into pojo folder, pojo class must be defined in default package.
When pojo class is defined some package, following link is helpful.
http://axis.apache.org/axis2/java/core/docs/pojoguide.html
Thanks to shashankaholic for sharing this link.

Related

How to create Class Mediator in wso2 esb /

I would like to create class mediator. I tried with ordinary java class i put into components/lib folder then i restart this system.
Can anyone tell me step by step procedure.
Write a class which implements org.apache.synapse.Mediator and override the mediate(MessageContext mc) method and create a jar file.
public class SimpleClassMediator implements Mediator {
private String varible1="10";
private String varible2="10";
public boolean mediate(MessageContext mc) {
//To test you can print something here
return true;
}
//getters and setters
}
Copy the jar to ESB_HOME/repository/components/lib and start the ESB.
Then in synapse config you can call this mediator as follow.
class name="packageName.ClassName"
You can create class mediator easily by extending the "AbstractMediator".
Mediator can be an OSGI build or jar file. Both can be deployed with WSO2 ESB. If You need to deploy the Jar file in to /repository/components/lib directory. If it is an OSGI bundle, it must be deployed in to /repository/components/dropins directory. If there are any external dependent libraries, you can put them it to /repository/components/lib directory
Update the synapse configure with the full qualified class name
You can find sample more detail from here. It contains a sample mediator code that you can look in to.
1. First create a Maven module e.g org.wso2.carbon.mediator and then create e.g ESBMessageMediator class which is extended from AbstractMediator.
2. Above maven module can be configured as OSGI budle or jar file.
3. Build the module using maven.
4. If it is OSGI bundle put it in to the /repository/components/dropins else put it to the
/repository/components/lib
5. configure synapse.xml file located in the "/repository/deployment/server/synapse-configs/default"
e.g <class name="org.wso2.carbon.mediator.ESBMessageMediator">
<property name="defaultPercentage" value="10"/>
</class>
6.Run the ESB and try to create a proxy service by adding the above meaditor as class mediator.if it load succesfully it is done.
you can read about class mediator in WSO2 in this site [1]
You can write the logic in the mediate() method :)

JBoss WebServices and EJB

My application should show a list of stuff over RESTful WebServices.
This list of stuff is generated via an EJB which is deployed in JBoss AS 6 in a .jar.
My question is, how do I get this list of stuff in order to show it via Web Services?
If I try to inject #EJB in the stateless bean annotated with #WebService, and try to invoke the method that generates the list, I get an error saying that #EJB cannot be resolved (or imported). (fixed it, needed to modify maven dependencies).
Now I get a NullPointerException when I call the supposedly injected EJB...
I am using the webapp archetype from Maven, which contains an EAR, a JAR and a WAR.
I am at a total loss here, been trying to figure this for almost a week.
Thanks in advance!
--EDIT-- code and typo fixed
This is my stateless bean which SHOULD be exposed as a WebService (according to:
http://www.adam-bien.com/roller/abien/entry/restful_calculator_with_javascript_and )
#Stateless
#Path("/MyRESTApplication")
public class HelloWorldResource {
#EJB
private TestBean testBean;
#GET()
#Produces("text/plain")
public String sayHello(String name) {
return testBean.doMoreStuff();
}
}
the doMoreStuff() function simply returns "HELLO!".

How do I use CXFNonSpringJaxrsServlet with a serviceBean instead of a serviceClass?

I am trying to use Apache CXF with JAX-RS to serve as an embedded REST endpoint within a larger application. I cannot use spring configured CXF because my application needs to manage the lifecycle of the Jetty instance and servlets.
The example here shows how to do this with a service class name, but in my application it will be roundabout and ugly to pass a classname rather than a bean. Can anyone point me toward a way to use a bean here?
You have to leave CXFNonSpringJaxrsServlet create your instance, but you can configure it (=bind it to outside world) by extending CXFNonSpringJaxrsServlet#configureSingleton
See this post: CXF/Jetty equivalent of the following Jersey/Jetty code for a solution. Tested with CXF 3.0.3 and Jety 9.2.5.v20141112.
This is how it's done
Object serviceObject = // your JAX-RS service object
JAXRSServerFactoryBean rs = new JAXRSServerFactoryBean();
rs.setServiceBeanObjects(serviceObject);
Server server = rs.create();

Access EJB 3.0 as an EJB and as a web service on Websphere 7

I want to deploy an EJB 3.0 stateless bean to WAS7 so I can access it as an EJB through a local interface and also as a jax-ws web service.
My bean looks as following:
#Stateless
#WebService
public class UserManagerImpl implements UserManager {
public UserManagerImpl() {
}
#WebMethod
public String getName(){
return "UserName";
}
}
The problem is that if I package it into an EJB-JAR and deploy, it doesn't work as a web service on WAS-7.
The only working configuration for me is if I put the EJB-JAR into a EAR and put this EJB-JAR to a WAR that is also in the EAR, like this:
EAR/
|--EJB-JAR
|--WAR/
|WEB-INF/lib/
|EJB-JAR
So my bean is duplicated.
Is there any problem with this design? If so, is there a better solution?
If your application contains #WebService annotated EJBs, then you need to process the EAR with the endptEnabler tool shipped with WebSphere before deploying it. Note that this doesn't apply to #WebService annotated classes in Web modules.

Axis2 : Generting Wsdl from java code

I have written a simple java class as shown below :
public class Simple {
public String echo(String rest) {
return rest;
}
}
I have written a Simple Services.xml file and deployed it inside the META-INF Folder and generated the .aar file for this and deployed it inside the Axis2 war file , and i got a wsdl from this
for example say
http://localhost:8080/axis2/services/SimpleService?wsdl
Now my question is , i have seen some examples where , java2wsdl.bat is uesd with the combination of Java File ( wsdl2java -cn javaclass file) , which then generates the wsdl file from this java class .
Please tell me what is the correct approach to generate the wsdl file , so that i can write a client for it and deploy it as a war file ?
Please share your ideas . Thank you very much in advance .
you need to deploy it as a service if you need to create a web service. So that others can access as well. But you intention is only to generate the wsdl file java2wsdl tool is enough.