I am learning how to implement web services in Java. Following the example in O'Reilly's book "Learning Java," I downloaded a WSDL file (see http://bit.ly/13moiTh) for a weather service at cdyne.com and generated a set of classes using the wsimport tool.
The first problem was that when I generated a JAR file and referenced it in the Eclipse project, the classes were not recognized. I had to use wsimport -keep and individually copy all source files into the project to make it build.
Next, to make sure that the service was available, I constructed a simple HTTP POST client based on the code from the book. I could successfully access the getCityWeatherByZIP service with that code, so there was no connectivity or authentication issue.
Finally, I tried to access the getCityWeatherByZIP and getCityForecastByZIP services using the automatically-generated web services client code. Both silently failed, i.e. the isSuccess() methods returned false and all response fields were null:
Weather service = new Weather();
WeatherSoap weatherSoap = service.getWeatherSoap();
WeatherReturn weather = weatherSoap.getCityWeatherByZIP(ZIP);
if (weather.isSuccess()) {
System.out.format("%s, %s : %s : Temperature: %s, Wind: %s\n",
weather.getCity(), weather.getState(), weather.getDescription(),
weather.getTemperature(), weather.getWind());
}
else {
System.out.println("Failed to obtain weather");
}
In stepping through the code, in getCityWeatherByZIP() I discovered the following NoSuchMethodException:
com.sun.xml.internal.ws.api.message.Packet.setHeaderList(com.sun.xml.internal.ws.api.message.HeaderList)"
This exception occurs in line that says (in the Debug perspective of Eclipse):
"SEIStub.invoke(Object, Method, Object[]) line: not available"
Clearly, the Packet.setHeaderList(HeaderList) method does not exist, which is also corroborated by the documentation of the non-internal class:
https://jax-ws.java.net/nonav/jax-ws-20-fcs/arch/com/sun/xml/ws/api/message/Packet.html
I am using the latest JDK 1.7 and Eclipse Version: Kepler Service Release 1, Build id: 20130919-0819.
I do not know how to fix this problem. Any help would be appreciated.
In addition to the source code from the book, you also need a copy of the JAX-WS web service code in order to compile and run. You update the Build Path inside Eclipse to reference any jars for the JAX-WS web service, and it sounds like Eclipse doesn't have a copy on the classpath.
JAX-WS is the specification but you will need an actual implementation of JAX-WS in order to run, possibly the Reference Implementation?
Related
Okay. So i'm taking over a very very old system that uses Groovy, and this application is connecting to a third party web service via its configuration file with the entry like this: (this is for prd)
webService.wsdlUrl = "jar:file:/lib/MyWebService.jar!/META-INF/wsdl/MyServices_live.wsdl"
It has its own set of groovy configuration files for qa and prd. Qa looks like this:
webService.wsdlUrl = "jar:file:/lib/MyWebService.jar!/META-INF/wsdl/MyServices_qa.wsdl"
These MyServices_live.wsdl and MyServices_qa.wsdl files contain the path to the actual web service url (for prd and qa respectively) which is the one that needs to be replaced for both instances.
I already have the new url. So what did I do? I don't have enough experience doing this so I had to do some research. Apparently, I can use "wsimport" to connect to the new web service url and append ?wsdl to the end of this url so I can generate a jax-rs web service client. I was able to produce a set of java codes that I eventually learned that theyI thought problem solved. I just need to compile these java codes and jar the classes, so I'll have an updated MyWebService.jar.
Now, I realized with what I have done, the wsdl parameter is embedded in the code
#WebServiceClient(name = "Services", targetNamespace = "http://blahblah/", wsdlLocation = "https://newhostname.com/Service?wsdl")
With this approach, I would create 2 jars, 1 for prd and 1 for qa which won't be the most ideal thing to do. We would like to retain the previous capability of controlling where the web service client (inside the jar) will point to by using a parameter (e.g. just like here... the wsdl was specified jar:file:/lib/MyWebService.jar!/META-INF/wsdl/MyServices_live.wsdl ).
Again, to highlight the architecture, the application is running in Groovy and it is using a jar file to access some third party services.
I haven't really done any Groovy development, so I would like to as much as possible not touch any Groovy code.
Would you have any idea of how i can go about this problem?
I am very new to the building of web-services, so please forgive my ignorance.
I have been given some an .wsdl files with some .xsd files that it imports.
I am told that a web-service can be created from the .wsdl file by using wsdl2java from the apache axis2 project.
The web-service I am trying to build is expecting to have data pushed to it and I would like to test it that I have the process right for data to be pushed to a web-service that I created.
The basis for my actions have been from here, but not too sure how much of it is applicable.
I am on a MacOSX but also have access to an ubuntu system too.
the steps I have taken so far are:
cd /directory/of/wsdl/file
wsdl2java.sh -uri tmp.wsdl -d adb -s
This creates a build.xml file and src directory
I then try and run
ant
or
ant jar.client
After this I am not too sure what to do, in order to get the web-server running so that I could test it...any suggestions would be greatly appreciated.
Thanks in advance.
In SOAP web service:-
The basic concept in web service is that it has consumer and producer.
A consumer is one which consumes a web service and a producer is one which produces a web service. A producer publish its service so that consumer can consume it. It basically publishes a wsdl file so that you can create a client code or jar out of it and can directly call it from your code. You can use soap UI to call the web service directly as well. If you are looking for generating producer code from wsdl as well it will not be good enough since it will not provide business logic to you and you need to implement it by yourself. This is not a recommended approach. Generally first java implementation is written and based on it a wsdl is created from which client jars are created for the clients to use the web service in their code. For directly testing the producer soapui is used.
If you want to create producer it is a straight forward process. Need to create a dynamic project in eclipse-->create a class-->use #WebService(serviceName="xyz") on class and similarly on method level define #WebMethod. Deploy it as run on server and you are done with your Hello World Web service producer.
For creating the client:-
Lets take an example of a published wsdl on the net as :-
http://www.webservicex.net/geoipservice.asmx?WSDL
First you need to create the client jar or java classes as :-
wsimport -keep -s C:\wsdl http://www.webservicex.net/geoipservice.asmx?WSDL
Look at the documentation or look at the service name in the wsdl.
It will be GeoIPService.
Now in your class call the webservice method as:-
package com.soap.client;
import net.webservicex.GeoIP;
import net.webservicex.GeoIPService;
import net.webservicex.GeoIPServiceSoap;
public class SoapWebServiceClient {
public static void main(String[] args) {
GeoIPService ipService = new GeoIPService();
GeoIPServiceSoap gp = ipService.getGeoIPServiceSoap();
GeoIP ip = gp.getGeoIP("117.198.208.1"); //google.com
System.out.println(ip.getCountryName());
}
}
Now similarly for local wsdl you can create classes and jars by
using axis2 or simply wsimport
Put your wsdl and schemas in a folder as shown below:-
C:\wsdl>wsimport -keep -s C:\wsdl C:\wsdl
C:\wsdl>wsimport -clientjar client.jar C:\wsdl
It will create a client for you. Look at the service name and similarly can test the deployed service from java code as shown above.
For testing using soapui you use need to download it and create a new soap project. Give any name and browse to your local drive where all the schema and wsdl is present. It will create all the requests for your. You need to fill in the values in the request parameters ("?") and run the service. If everything went well it will display a result.
Note:-
wsimport is a command line tool for the JAX-WS reference implementation. The JAX-WS RI uses JAXB for data-binding.
Axis2 merely implements the JAX-WS API to some extent, so the Java artifacts generated can be quite different compared to those generated by the JAX-WS RI. Also Axis2 doesn't use JAXB but instead offers the choice of ADB (default), Apache XmlBeans, or JiBX for data-binding. The most popularly used are either xmlbeans or JAXB.
You lookup the wsdl file from publishing URL and reverse engineer the webservice to generate the types so use wsimport
wsimport -d . -p servicesource -keep tmp.wsdl
Short version: A restful spring web service crashes when I include a dependency: com.google.gdata: core: 1.47.1
Long Version:
I was trying to make a restfull web service that consume certain information from a spreadsheet in google drive
this is my sequence of steps:
preparing classes that made the connection and the data obtained from drive (not web, only backend classes, unit and integration tests included): all ok
prepare a restfull web service with spring, basically download a spring tutorial (http://spring.io/guides/tutorials/rest/3/) and execute: all ok
then remove tutorial's business classes and include my components, change controllers to invoke my components, plus add gdata dependence in file graddle.build, try execute: houston we have a problem
It's strange, when start app context, log print something like this:
C:\Users\Grubhart\Documents\proyectos\error_Rest_Gdata\complete\src\main\java\com\yummynoodlebar\config\WebAppInitializer.java:39: error: can not find symbol
servletContext.setInitParameter ("defaultHtmlEscape", "true");
^
symbol: method setInitParameter (String, String)
location: Variable of type ServletContext ServletContext
but when the rest app is just downloaded (whitout my code, neither gdata dependency) it works, the only thing I did was add my code and the google api dependence, so I started to see what could cause the error
remove all my code (but leave the gdata jar) and... wait for it.. same error,
remove gdata dependency: it works
then add gdata dependency again and test: the same error again
So I think that by including the gdata jar does something that prevents start the entire app context
I created a repo on github to illustrate the error:
https://github.com/Grubhart/error_spring_restWS_gdata
the master branch has the code of a service that works without gdata dependence
gdata_error branch as you can imagine has added gdata dependency (only dependency, no extra code) in gradle.build file:
compile 'com.google.gdata: core: 1.47.1'
and presents the error
no need install anything (even gradle) only have jdk, download the code and run it as stated in the readme file to see errors
i do my homework, look in google, stackoverflow (great site!), spring forum but can't find nothing
if anyone has experience with this problem, or know where i can found more information would be great if you can share experiences or if you know where to look for more info about this error
The original post doesn't contains:
yummynoodlebar\config\WebAppInitializer.java:39: error: cannot find symbol
servletContext.setInitParameter("defaultHtmlEscape", "true");
ServletContext needs import javax.servlet.*; Maybe the error is for that.
Since the spring context configuration in java classes for web applications works with Servlet 3.0 maybe you have overwritten troubles between some dependencies that comes with gdata which may do use of dependencies other than the servlet version you are using to deploy the application or which it was originally configured, I hope this helps you!.
i followed this article: http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
so i have:
HelloWorld http://pastebin.com/BJ3QA7pR
HelloWorldImpl http://pastebin.com/RM5SBZ5C
HelloWorldPublisher http://pastebin.com/H525WevK
which serves as the endpoint.
on the other side i have the client which i generated with wsimport:
HelloWorld http://pastebin.com/g07H1exf
HelloWorldImplService http://pastebin.com/f0YWMiYt
this runs fine in eclispe without alfresco being involved. however, i want to call the webservice from alfresco (from java backed web script for example)
i tried to copy the client side stuff to my amp file and calling it from a webscript but it fails!
Caused by: java.lang.IncompatibleClassChangeError: Class com.ibm.wsdl.DefinitionImpl does not implement the requested interface javax.wsdl.extensions.AttributeExtensible
Webscript http://pastebin.com/7JksRdtU
1 - is there a more elegant way to configure the access to the wsdl by defining a spring bean (spring-ws) or such
2 - why is it not working? full trace: http://pastebin.com/ak1qzygA
using alfresco community 5.0.a
thanks
You will see IncompatibleClassChangeError usually when the dependancy/library jar has changed. Hence the method/code dependant on the library has to be recompiled against the changes.
Guessing the problem here has much to do with some dependancy jar being mispicked or an older version of jar present or one jar prioritized over the other. A look into the jars containing 'com.ibm.wsdl.DefinitionImpl' class in your classpath should be of some help.
When I create a new Web service using RSA 7.5 IDE and Web Sphere 7.0 server from a Web Application, then I can see a few auto-generated files created by this process, namely:
1) For the service, a SEI file is created
2) For the models, ser, deser and helper files are created.
But I cant understand what are the use of all these SEI, ser, deser and helper files.
Any valid explanation on this will be much appreciated.
BOUNTY EDIT:
Bounty-Edit:
Since I did not get any response I would like to ask this question again - offering a bounty to encourage an in-depth answer. I would love to know how and when are these files used internally?
Regards,
Service Endpoint Interface (SEI):
SEI is the Java interface corresponding to the Web service port type
being implemented. It is defined by the JAX-RPC, which specifies the
language mapping from WSDL 1.1 to Java. Ref
Or
A service endpoint interface (SEI) is a Java interface that
declares the methods that a client can invoke on the service. Ref
These ser,dser,helper are helpers to convert an XML document into a java object and vice versa (WebServices). Ref
Files generated in the server project: (WebSphere Application Server 6.1 Ref)
According to the settings made during the run of the wizard, the following files in the WeatherJavaBeanWeb project have been created:
Service endpoint interface (SEI): itso.bean.WeatherJavaBean_SEI.java is the interface defining the methods exposed in the Web service.
WSDL file: /WebContent/WEB-INF/wsdl/WeatherJavaBean.wsdl describes the Web service.
Deployment descriptor: webservices.xml, ibm-webservices-ext.xml and ibm-webservices-bnd.xml. These files describe the Web service according to the Web services for J2EE style (JSR 109). The JAX-RPC mapping is described in the WeatherJavaBean_mapping.xml file.
Data mapping files: The helper beans in the itso.objects package perform the data conversion from XML to Java objects and back.
A servlet is defined in the Web deployment descriptor to invoke the JavaBean.
Hope this information help you.
Those files are related to the WebSphere mapping between Java, WSDL, and XML. They are automatically generated, and should not need to be edited. You should pretend they are not there (except if they are not there you may have trouble deploying...).
SEI - Service Endpoint Interface
ser - Serialize
deser - Deserialize
helper - ?
Here are some psuedo-helpful links, that may provide some more insight into your question:
IBM Technotes
WebSphere v6.1 Handbook (check Chapter 15 -> Creating a Web Service --> Generated Files)
All these files are basically generated for webservice.
A web service ia basically a port between 2 running applications independant of the framework or language.
Leta say if you are using java from one side of web service then for complete compilation the java end would need some class files that have those methids which you wish to call on the service.
For this a stub is generated. This stub is basically an interface(SEI).
Also websphere needs additional files for implementing the webservices functionality, thus tge helper files.
This is basically the summary of it.