3

I've looked high and low for a solution to this problem

I have a java project (which I've inherited). It is essentially a RESTful wrapper to a SOAP web service. I'm not entirely sure why other than they were having problems with PHP connecting to their Webservice so created a Restful service which connected to the WS as a client.

The problem is that the jax-ws autogenerated web services artifacts/classes are being hardcoded to a local path as the machine which compiles the project. Here is the example of annotations created in the java file which is auto generated by jax-ws upon project compile.

/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.10-b140803.1500
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(
name = "flahImplService", 
targetNamespace = "http://flah.com/", 
wsdlLocation = "file:/C:/Users/WindowsUser/PathToNetBeansProjectFolder/flah.wsdl")
public class flahImplService

}

It seems to be linking to the online WSDL and building the files based on that.

The only other important thing i can find is that in /nbproject/jax-ws.xml there is a xml such as this:

<?xml version="1.0" encoding="UTF-8"?>
<jax-ws xmlns="http://www.netbeans.org/ns/jax-ws/1">
  <services>
    <service name="flahImplService">
      <implementation-class>com.service.management.flahImplService</implementation-class>
      <wsdl-url>https://blah.com/flah.wsdl</wsdl-url>
      <wsdl-url>blah.com/flah.wsdl</wsdl-url>

Where should I be specifying a path to replace this auto generate and hardcoded local WSDL location?

Edit: btw, when I run this project locally it of course works because the path to the wsdl file is ok, but when deployed to the application server it fails.

wired00
  • 13,930
  • 7
  • 70
  • 73
  • also look at [this question](http://stackoverflow.com/questions/4455195/how-to-avoid-the-need-to-specify-the-wsdl-location-in-a-cxf-or-jax-ws-generated) – Puh Dec 05 '14 at 14:05

2 Answers2

1

actually you shouldn't use generated client... it's just for testing. use something like this to create your client:

import java.net.URL;
import javax.xml.ws.Service;
...

URL wsdlURL = new URL("http://localhost/hello?wsdl");
QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
Service service = Service.create(wsdlURL, SERVICE_NAME);
Greeter client = service.getPort(Greeter.class);
String result = client.greetMe("test");

also take a look at Spring cxf client configuration

Puh
  • 305
  • 1
  • 10
0

How are you referencing the web service client?

If you're using @WebServiceRef annotation to have the container inject your service reference into your container managed class. In this case you can include a copy of the WSDL in your own web project (for example, WEB-INF/wsdl/flah.wsdl) you can use the wsdlLocation attribute of @WebServiceRef to point to this location instead. See javadocs for WebServiceRef annotation. The tricky point from there (in my opinion) is what classes can use @WebServiceRef - must be container managed (Servlet, ServletFilter, EJB, JSF managed-bean, etc). If your RESTful code isn't container managed but eventually gets access to HttpServletRequest, a trick I've used occasionally is to add a servlet filter with @WebServiceRef to get the client injected from the container and placed it for use down-stream as a request attribute.

Scott Heaberlin
  • 3,364
  • 1
  • 23
  • 22
  • Hmm not sure, as far as I can see it certainly isn't injecting any service references via @WebServiceRef, in fact that annotation doesn't exist within the project at all. It just seems to directly instantiate an object which is created from the auto generated jax-ws files. They are located under "Generated Sources (jax-ws) as Puh says above, these are just for testing? I'm thinking i should just recreate the service my self, its actually only one method wrapped – wired00 Oct 27 '14 at 06:33