I am using Apache Axis to connect my Java app to a web server. I used wsdl2java to create the stubs for me, but when I try to use the stubs, I get the following exception:
org.apache.axis.ConfigurationException: No service named <web service name> is available
any idea?
According to the documentation linked to by #arnonym, this exception is somewhat misleading. In the first attempt to find the service a ConfigurationException is thrown and caught. It is logged at DEBUG level by the ConfigurationException class. Then another attempt is made using a different method to find the service that may then succeed. The workaround for this is to just change the log level on the ConfigurationException class to INFO in your log4j.properties:
log4j.logger.org.apache.axis.ConfigurationException = INFO
Just a guess, but it looks like that error message is reporting that you've left the service name blank. I imagine the code that generates that error message looks like this:
throw new ConfigurationException("No service named" + serviceName + " is available");
It is an exception used by Axis' control flow.
http://wiki.apache.org/ws/FrontPage/Axis/DealingWithCommonExceptions
--> org.apache.axis.ConfigurationException: No service named XXX is available
This is what my code looks like. It seems to work fine.
Are you using a service locator or just creating your service?
SomeServiceLocator locator = new SomeServiceLocator();
SomeService service = null;
try
{
service = locator.getSomeServiceImplPort();
}
catch (ServiceException e)
{
e.printStackTrace();
}
I don't know what version of Axis you're using but I'm using Axis2 for both server and client and the Java2WSDL create a default endpoint for the service on localhost. If you create the client stub with WSDL2Java, the default constructor of the stub will then point to localhost. If the service is on other endpoint you must use the constructor with the endpoint as parameter...
Maybe the problem is not that at all but as said on other answers, without the WSDL you're using as WSDL2Java input it's hard to say.
Related
So, I've created a client stub application with Apache CXF from a WSDL. The process was relatively straight-forward. I did it within SoapUI interface. I supplied the WSDL location, told CXF to generate the client stub and hit okay.
Then, I imported the project into Eclipse, added the Apache CXF libraries, configured some security options, certs and whatnot.
I wrote a main with a few test calls to my webservice, and... it worked.
Now my problem is that I don't know WHY it worked. To be more specific, when I hit run in Eclipse, the debug output clearly shows that there are CXF classes being invoked.
INFO: Loaded configuration file cxf.xml.
and
org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
In my main() I'm invoking the
MyServices ss = new MyServices(wsdlURL, SERVICE_NAME);
port = ss.getWSHttpBindingMyService();
But the MyServices class extends javax.xml.ws.Service and there's nothing that hints to CXF.
wsdl2java also generated a MyService interface and a MyServiceImpl class that sits in the same package. It looks like a good candidate. In my main() I can write stuff like port.someMethod(someRequest). If I ctrl-click on someMethod and follow the implementation, it actually brings me to MyServiceImpl class but there's only dummy code there!
public Boolean someMethod(SomeRequest request) {
LOG.info("Executing operation");
System.out.println(request);
try {
Boolean _return = null;
return _return;
} catch (java.lang.Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
So there must be some configuration somewhere that is telling the runtime which implementation to use. But I cannot figure out where or which one it is.
Thanks
Whether you use cxf or wsdl2java to generate the client code .
The client code will be generated as per the J2EE specification.
The code generated is just the declaration of service , the implementation of service will be on server.
The client code make uses of the webservice wsdl location to find the service and the operation exposed by it.
Check in your MyServices , You will see your service URL.
Ex
wsdlLocation = `"http://127.0.0.1/bookstore/services/search?wsdl"`
Thanks
In my Dropwizard project, I'm defining a generic ExceptionMapper<WebApplicationException>:
environment.jersey().register(new WebApplicationExceptionMapper());
...but this doesn't seem to catch any of the 404 errors for unmatched paths.
Without defining five defaultHandler() methods for every single resource, how do I catch all 404s so I can return my own error page or some JSON?
So, if I had a service with one resrouce, say, /docs, this is the situtation:
/myservice/docs/helloworld doesn't match any #Path defined in my DocsResource. It returns a generic Jetty 404 page (not what I want)
/myservice/doesntexist returns my own error resource with the exception mapper (this is what I want everywhere)
what you need to do is to set a different Error handler. The 404's you are seeing when hitting a non-existing path, are not handled by jersey. Jersey maps exceptions for resources, but you in fact never hit the resource in the first place. This is where you will need to define an error handler:
In DefaultServerFactory, you need to overwrite:
protected Server buildServer(LifecycleEnvironment lifecycle,
ThreadPool threadPool) {
final Server server = new Server(threadPool);
server.addLifeCycleListener(buildSetUIDListener());
lifecycle.attach(server);
final ErrorHandler errorHandler = new ErrorHandler();
errorHandler.setServer(server);
errorHandler.setShowStacks(false);
server.addBean(errorHandler);
server.setStopAtShutdown(true);
server.setStopTimeout(shutdownGracePeriod.toMilliseconds());
return server;
}
(This class is in AbstractServerFactory).
You then can implement your own ErrorHandler and make it do whatever it is you want it to do.
For testing, open org.eclipse.jetty.server.handler.ErrorHandler and set a breakpoint, then try and hit a non-existing URL. It will stop there and you can see how jetty handles this sort of thing.
I hope that helps.
If you need help overwriting default DW functionality, you can look at a similar post where I described how to overwrite loggers:
Dropwizard doesn't log custom loggers to file
Cheers,
Artur
This question is regarding Atmosphere framework.
I am trying to broadcast a message to clients as soon as any event occurs (i.e. Notification).
I am not able to get Hazelcast broadcaster to work for publishing data from server to cliens. I tried using following hazelcast broadcaster implementation (atmosphere-hazelcast-2.3.0-RC5.jar).
https://github.com/Atmosphere/atmosphere-extensions/blob/master/hazelcast/modules/src/main/java/org/atmosphere/plugin/hazelcast/HazelcastBroadcaster.java
Atmosphere automatically detects atmosphere-hazelcast-2.3.0-RC5.jar file when put in classpath. Hazelcast instance starts properly when I start my Tomcat 7.
But as soon as a call is made to factory.lookup(uniqueId) to lookup for topic to broadcast message, I get following exception:
Exception in thread "Thread-3" java.lang.IllegalStateException: Invalid lookup class org.atmosphere.plugin.hazelcast.HazelcastBroadcaster. Cached class is: org.atmosphere.cpr.DefaultBroadcaster
I am getting the broadcaster object as follows:
AtmosphereFramework framework = (AtmosphereFramework) getServletContext().getAttribute("AtmosphereServlet");
BroadcasterFactory bf = framework.getBroadcasterFactory();
Broadcaster b = bf.lookup(uniqueId);
Is this the correct way to get the broadcaster in a simple servlet or one must use #Inject to inject broadcaster? (In case of simple servlet I am not sure how to use #Inject to inject a broadcaster).
Note that if I do not use HazelcastBroadcaster, then factory.lookup(uniqueId) call works well (Using default broadcaster) and messages are sent to client.
Has anybody faced similar issue? Will appriciate any pointers to solve this.
Thanks !
Looks like a bug to me with 2.3.x-RCx. Please file an issue https://github.com/Atmosphere/atmosphere
-- Jeanfrancois
Am pretty new to web services and have been trying to implement Soap Faults. I used Apache Axis2 to generate webservice in the following manner.
public interface XYZ{
public String myMethod(User[] user)
}
Here I have created a User class with some variables so that I can generate User object at .Net environment to pass User[] of objects.
Public class Webservice implements XYZ
{
Public String myMethod(User[] user){
//My implementation
}
}
Now, I created a dynamic project using Eclipse and with the help of Axis2 plugin I created webservice for my "Webservice" class which generates wsdl file. I deployed the webcontent in the Tomcat folder and able to access the WSDL file in the .Net environment. I am able to pass array of objects (User[]) from .Net to Java and able to do my task. Now, I need to implement Soap Faults in Java which I am not sure how to implement.
Can anyone help me with an example or tutorial ?
Your best bet is to Google for something like "jax-ws faults". For example:
http://www.ibm.com/developerworks/webservices/library/ws-jaxws-faults/index.html
You can also implement an error handler, as discussed under "Using handlers in JAX-WS Web services" here:
http://axis.apache.org/axis2/java/core/docs/jaxws-guide.html#BottomUpService
Most frameworks will trigger a SOAP fault when you throw an Exception in the method implementing your operation. That will not give you much control on the SOAP fault content though.
See here for some details on Axis
Generally, You don't need any specific coding for implementing SOAP fault.. Whenever there is any exception thrown by the method (here myMethod in your example.), axis will automatically generate SOAPFault element in the resulting response. The exception is actually wrapped into AxisFault exception and sent to the client.
See here a i.
I'm trying to write a simple web service client to interact with my simple web service which only returns a user id that's passed in. So I created a web service client in eclipse and generated a few files for me; wsCall, wsCallBindingStub, wsCallProxy, wsCallService, wsCallServiceLocator. The stub is the conly class I found that has my web service methods in it, because my ws is simple at this stage?
So I want to invoke the call, what do I need to make the call?
I've seen all the examples online have the try-catch for a remote exception or Axis fault, then the classes are instantiated (including a response class, to deserialize?) and make the ws call via the stub class. Is that all I need to call for my case?
wsCallBindingStub stub = new wsCallBindingStub();
String retString = stub.sayHi(1); // 1: my user id
return retString;
Thank you!
Ahh I figured it out, I was getting an error because my wsdl uses the hostname and I needed to specify the ip.. as for the code needed it was pretty much identicle;
wsCall ws = new wsCallServiceLocator().getWsCallPort();
result = ws.sayHi(x);