Get Request Parameters from XML using WebFilter
Asked Answered
I

1

8

I´m developing a Web Service, using Glassfish, using SOAP. I have several web methods, and I want to get introduce my webmethod name and his parameters to http head request.

For example:

I have this path:

context: WebServices

webMethod: makeSomething

parameters:a=2

So I create a class named ProfilingFilter:

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException {
           
    if (request.getContentLength() != -1 && context != null) {
        ((HttpServletResponse) response).addHeader("Operation", -->PATH+PARAMETERS);
        //  ((HttpServletResponse) response).addHeader("Operation", -->makeSomething?a=2);
    }
    
}

It´s possible to use servlet response or servlet request to get this information?

If not, How can I do this?

Interpol answered 8/5, 2015 at 10:45 Comment(7)
As this is a SOAP service there is NO HTTP read request. All SOAP operations are done via the HTTP PUT method. My suggestion is that you install something like WireShark and capture the XML request or even better use SOAP UI to capture the XML request and have a look at an actual request. This will give you some insight into how you will have to go about achieving what you want.Nibelungenlied
Your question is not very clear. It looks like you're trying to add HTTP headers to the web service request, before it gets to your web service processing bean. Is that correct? Are you running a JAX-WS webservice? What do you mean by "web method"? Are you referring to HTTP operations or actual web service operations, as in a WSDL?Frierson
No. When I make a request I want to add Soap Message Response to http header, via Http Servlet Response, or something similar.Yes I´m running jax-ws. WebMethod is a method inside my WebService.Interpol
You want to stick the full SOAP response envelope into an HTTP header? Why? Whatever the reason, you probably won't be able to, as there is a limit imposed by browsers, on the size of HTTP headers. Are you interested in a SOAP header instead?Frierson
I don t want full response. Just some information about soap content messageInterpol
None of the stuff in this question makes sense: your question title says that you want to get request parameters from XML using a webfilter; then your code shows you doing stuff to the response HTTP headers.Frierson
please clarify your question more .Baltimore
O
0

You will need to access the HTTP request body. There is only one caveat: You can read a stream only once which means you will have to do some tricks in order to keep the SOAP request working. Take a look here:

http://wetfeetblog.com/servlet-filer-to-log-request-and-response-details-and-payload/431

This example covers reading a HTTP request and then passing the original data down the filter chain.

HTH, Mark

Oligoclase answered 28/5, 2015 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.