Ignore missing method in JAX-WS client - java

I have a model that is used to create a Web Service endpoint on a server. The same model is used for the client. However when a new operation is added to the server but the client still uses the older model, service creation fails with an exception like the following (line breaks added for clarity):
Exception in thread "main" javax.xml.ws.WebServiceException:
Method someNewMethod is exposed as WebMethod, but there is no
corresponding wsdl operation with name someNewMethod in the
wsdl:portType{http://example.com}MyService
I understand the problem but is it possible to ignore this? I'd like to be backwards compatible when consuming the Web service. As long as methods are merely added this should work just fine most of the time.
The problem occurs in the getPort method:
Service s = Service.create(
new URL("http://example.com/foo?wsdl"),
new QName("http://example.com", "MyService"));
MyService m = s.getPort(MyService.class);

Just for reference.
You can also annotate the method with
#WebMethod(exclude=true)
This will make sure the method is ignored for comparing with the wsdl.

Use an local WSDL File:
The client App has an local WSDL File of the service e.g inside the jar file.
The you get it with
URL wsdlURL = this.getClass().getClassLoader()
.getResource("MyWebService.wsdl");
That worked for a App that i wrote. The server later extended an additional WSDL attribute, while the client still uses the local one.

I just deleted the webservice reference and created again using the interface.

Your Service class contains a static constructor with a local wsdl file variable. Check if local wsdl file has the someNewMethod. If not download the wsdl file from original Url and save to local.
The soap address location value at the end of the wsdl is also important.
Sometimes https turns to http.

Related

Communicating to a SOAP webservice with constantly changing targetNamespace

So there is a SOAP webservice. The targetNamespace in the WSDL dynamically changes based on customer's configurable string. Think of it like
targetNamespace="http://myservice."+ [CouldBeAnyString] + "domain.com"
I have two questions:
My basic research tells me that this is a pretty weird(bad?) practice for developing webservices. Thoughts ?
How does one write a client for such a webservice ? I have tested using jax-ws stub and it isn't compatible when targetNamespace changes. Any other suggestions ? I have been trying to understand dynamic client generation based on wsdl. Would prefer a nicer path though if one exists
Update:
I am only the client. Service is provided by someone else.
Same customer has multiple environments (eg test,production) where the service is hosted under different targetNamespaces
If the SOAPUI call works even if the targetNamespace has change, you could use a lightweight HTTP library called HTTPCLIENT.
With this library you don't need to generate client, since you are sending the SOAP envelope as a string, the way you would do via SOAPUI.
The downside is to work with Strings.
In theory, it is feasible to create such a Web Service client.
Steps:
Create Java artifacts based on the WSDL using wsimport.exe of JDK (see: http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example as a reference)
For the purposes of the code displayed below, I have used the Calculator WSDL provided by Microsoft
Create a "Dynamic Web Project" via Eclipse J2EE
Copy the Java artifacts created in step #1, under src folder of the project created in step #2.
Create a new Class containing you main method. Normally you would have something similar to:
String wsdlLocation = "127.0.0.1:8088";//Normally you should retrieve that value dynamically
Url url = new URL(wsdlLocation + "?wsdl");// ?wsdl is actually needed
String namespaceURI = "http://Example.org";//Normally you should retrieve that value dynamically
String localPart = "CalculatorService";// as specified in WSDL file (see name attribute of service tag)
QName qname = new QName(namespaceURI, localPart);
CalculatorService service = new CalculatorService(url,qname);
ICalculator iCalculator = service.getICalculator();
int response = iCalculator.add(1, 2);
System.out.println(response);
Now for the tricky part:
If you have followed the example with the aforementioned WSDL, you should now have several Annotated Classes having hard-coded namespace (e.g. ICalculator is annotated with:
#WebResult(name = "result", targetNamespace = "..."))//where ... is similar to http ://example .org
Using Java reflection modify all the hard-coded values at runtime (see an example here: https://stackoverflow.com/a/14276270/2625635 on how to modify Annotations)
The aforementioned solution should do the trick.
Most client frameworks allow you to create an interface for calling your client (i.e. they create a contract interface). They also provide an implementation for that interface and it is the implementation that has specific annotations or extends "SOAP aware" classes, while the interface is clean of such details.
From what you posted I assume the clients have the same interface, it's just the implementation namespace that's different? If yes, then write your application to use the interface then build a jar for each environment's implementation. When you deploy on test servers deploy with the test jar, while on production deploy with the production jar (i.e. pick a different implementation for the same contract depending on the environment).
Even if the framework you use doesn't create an interface for you, you can create one yourself and hide the various implementations behind an adapter of some sort.
You can also do something like edubriguenti suggested but I wouldn't go as far as working with strings. Work with SAAJ instead.

Getting CXF error: javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy

I have used CXF's wsdl2java to generate code from a WSDL file. I then build the code using the ant build xml file (also generated by CXF's wsdl2java).
When I run my code on my local Java 7 machine, all is well. When I run the code on a linux box in the cloud running Java 1.5, I get the following error:
javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy,
either Service instance or ServiceEndpointInterface com.a.b.TheService should have
WSDL information
I've had a search around and I can't find any information that might explain the error in my scenario. I'm not sure where to start on this one. Can anyone shed any light?
I mentioned Java versions above as it is an obvious difference, but it may have nothing to do with the problem.
UPDATE: Adding in the code below as a result of Syon's request:
private static final String servicesNamespace = "http://www.serviceprovider.com/services/2009/03/02";
private static final String servicesNamespaceSchema = "http://www.serviceprovider.com/services/2009/03/02/schema";
private static String SERVICE_NAME = "TheService";
private QName SERVICE_QNAME;
private TheService m_theService;
...
SERVICE_QNAME = new QName(servicesNamespace, SERVICE_NAME);
I wrote this code quite some time ago, and at the time I wrote the comment below.
I've included it here in case it is helpful:
// The sample code creates an instance of the generated TheService_Service class.
// TheService_Service has references to the local WSDL file that it was generated from, and
// will report an error if it is not found. To prevent that error, we could:
// (1) ensure that the WSDL is available locally in the production environment in the location
// referenced in the generated Java
// (2) generate the Java from the WSDL located on the web rather than local WSDL, meaning that
// the WSDL referenced in the generated Java would be a URL to where it is located on
// serviceproviders's web site.
// (3) Rather than create an instance of TheService_Service, just create an instance of its
// super class, javax.xml.ws.Service, which has a static method to create an instance of it that
// does not require the location of the WSDL to be passed to it.
// I am going to choose option (3). Option (2) is a close second.
Service service = Service.create(SERVICE_QNAME);
m_theService = service.getPort(TheService.class); <-- Fails here
((BindingProvider)m_theService).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
Binding binding = ((BindingProvider)m_theService).getBinding();
((SOAPBinding)binding).setMTOMEnabled(false);
Thanks,
Paul
To my knowledge, JAX-WS/CXF always requires the WSDL. Could it be that you have the WSDL included on the classpath somewhere on your local machine but not on your linux box?
Regardless, you should be able to fix this issue by using the Service.create(URL, QNAME) method. The URL needs to point to the WSDL, you can use either the web service endpoint + ?wsdl on the end, or save a copy of the WSDL locally and point to that instead.
In your comment you mention referencing the WSDL on the web being preferable. Personally I would store it locally as this will improve performance when calling the web service. The framework won't need to make a call over the network just to get the WSDL every time you create the proxy.
This happens if he web service uses authentication. The WSDL cannot be read until the user name and password have been entered...
Faced with the same problem, it turned out, I was missing these depedencies:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.0</version>
</dependency>
Just adding them to my classpath solved the problem.
Maybe you had them already in the classpath under Windows?

SERVICE_OBJECT_SUPPLIER parameter is not specified error

I have developed a webService using axis2 and spring. When I request the
wsdl file from the webservice I get the right wsdl file, but when I want to
use a defined operation of the webservice (using a java client),
I get the following exception:
[CODE]org.apache.axis2.AxisFault: The SERVICE_OBJECT_SUPPLIER parameter is
not specified.
In your services.xml file you need to define following two properties.
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
beanname-that-expose-as-a-WS
Take a look http://axis.apache.org/axis2/java/core/docs/spring.html

Consuming Java Web Service from .NET

I have a web service written in Java now I want to consume that web service in the .NET world. I use the WSDL to add a proxy class to my .NET application but when I invoke the Java web service method the response is always null. Anyone familiar with this issue?
UPDATE 1:
Another thing I noted is that I opened one of the svcinfo files and found the following code:
<endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://fff.mywebserive/somewebservie" binding="basicHttpBinding" bindingConfiguration="DOC_TOI_Binding" contract="ServiceReference1.DOC_TOI_PortType" name="DOC_TOI_Port" />" digest="<?xml version="1.0" encoding="utf-16"?><Data
This does not look right to me!
UPDATE 2: Solution (Kind of)
The problem was that the response had a different namespace than used by the client proxy class. This way the object was never deserialized correctly. Once, I changed the namespace to match the response namespace it worked fine. But now if I update the web service reference I will again get the same issue as the namespace will be updated. What is a good way to solve this problem? The only solution I can think of is to ask the creator of the webservice to use the correct namespace.
Using .Net, we can add the java web service in our application using Service Referrence or Web Service Referrence.
Service Reference - This is a dedicated way of calling Microsoft WCF Web Services 3.5 and higher.
Web Service Reference - Way of referencing Non Microsoft Web Service and lower version of Microsoft webservice such as 2.0
We can also use Service reference in non Microsoft web service, we just need to modify some configuration in app.config such as Security Configurations()
Now, when Invoking the web service request method it always ends up with the NULL object response.
(This is caused by the discrepancy between the proxy namespace expected response and the actual xml namespace webservice response )
Sample:
Proxy Code
[return: System.Xml.Serialization.XmlElementAttribute("GetResponse ", Namespace = "http://AJ_TUASON.COM ")]
Public GetResponse Get()
{}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://AJ_TUASON.COM")]
public partial class GetResponse
{}
Actual XML Namespace Response
webservice:GetResponse xmlns:"http://AJTUASON.COM"
To resolve this issue, install fiddler2. This will helps you track and confirm that the web services are working fine.
Then, copy the actual namespace in the XML response from web service.
Paste the actual xml namespace response in proxy class of .NET:
Sample:
[return: System.Xml.Serialization.XmlElementAttribute("GetResponse ", Namespace = "http://AJTUASON.COM ")]
Public GetResponse Get()
{}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://AJTUASON.COM")]
public partial class GetResponse
{}
This will resolve the Null issue.
Note: Do not always rely on the tool that generates proxy class. Tools can surely translate but doing analysis is another thing - AJ
It suggests to me that either your WSDL or your client is incorrect. The client should not be able to tell from the WSDL what language it's implemented in. Check your namespaces.
SOAP UI is a very nice tool for testing SOAP services. I'd recommend it for sorting out this issue.
Looks to me like something tried to escape that snippet. You don't want > you want >
You need to make sure that the service and the client are using the same namespace. Communication is paramount here.

Invoke webservice using jaxws when the wsdl has more than one service

I'm trying to get hold of the FindService on this wsdl using jaxws.
I generated the classes just fine using wsimport.
But when i do:
FindService findService = new FindService();
i get the exception:
Exception in thread "main" javax.xml.ws.WebServiceException: {http://s.mappoint.net/mappoint-30/}FindService is not a valid service. Valid services are: {http://s.mappoint.net/mappoint-30/}CommonService
So, it seems that jaxws is only finding CommonService in the wsdl which is the first one declared in it.
Any idea how i can use the FindService ?
Thanks.
This appears to be a JAX-WS bug.
You can make a local copy of the WSDL, modify it so that FindService is the first service definition declared, and run wsimport against it. That worked for me.

Categories

Resources