How do I specify a parameter as part of every web service call?

Currently, every web service for our application has a custom parameter that is added for each method. For example:

@WebService
public interface FooWebService {
   @WebMethod
   public Foo getFoo(@WebParam(name="alwaysHere",header=true,partName="alwaysHere") String user, @WebParam(name="fooId") Long fooId);

 @WebMethod
   public Result deletetFoo(@WebParam(name="alwaysHere",header=true,partName="alwaysHere") String user, @WebParam(name="fooId") Long fooId);

   // ...
}

      

A service can have 20 methods, each with a first parameter as user. And maybe twenty web services.

We don't actually use the user argument in the implementations - in fact, I don't know why it is there, but I was not involved with the design and the person who had it there had a reason (Hopefully).

Anyway, I'm trying to straighten out this Big Dirt Ball.

I've already come a long way by wrapping webservices with a Spring proxy, which allows me to do some before and after processing in the interceptor (before there was at least 20 lines of copied boiler plate per method).

I am wondering if there is some kind of "message header" that I can apply to a method or package and that can be accessed using some type of handler or something outside of each method of the web service.

Thanks in advance for your advice, LES

+2


source to share


3 answers


Who or what is waiting user

for messages to bind to SOAP headers ? Are your web services guaranteed? Is this some kind of authentication header? Perhaps this was the original intention. In fact, someone has to answer these questions. Find someone. And if you find out that you will never need it, stop transferring it. But if you need it, I think it's better to add it (even if you don't use it yet), unless changing the WSDL is an issue (especially on the client side).



PS: I don't know how not to add a parameter using methods @WebParam(header=true)

in Java in order to generate WSDL with operations from <soap:header>

on their input. AFAIK, this is how JAX-WS works starting from Java.

0


source


If there is no reason why you need to have this variable as a parameter, you can use each of your superclass services. This spring superclass introduces MessageContext, ServletContext, ServletRequest, HttpHeaders or whichever is appropriate (maybe MessageContext for JAXWS) using either @Context annotation or @Resource annotation.



Then put some methods in this superclass to pull the user's information from the request.

0


source


If authentication is what you are trying to accomplish, you can manipulate contexts from predefined handlers like protocol or boolean handlers. For example. implement the SoapHanlder interface (which is the protocol handler), from there add this class to the handler chain for each service you offer. Very simple and powerful. This gentleman has the best tutorial out there on this topic.

0


source







All Articles