Can I intercept calls for my WSDL on Glassfish (or on any application server)?

I created the Java web service using annotation @WebServiceand deployed the service to the Glassfish server, which lives behind the proxy server.

The problem is that someone accesses our WSDL and looks at the location of the service endpoint address that they see

http://app server url/service...

instead

http://proxy server url/service...

I would like the proxy server URL to be returned to the address point of the WSDL service endpoint instead of the application server URL.

I am wondering if I can write a filter or listener to listen for WSDL requests and then change the address of the WSDL service endpoint with the proxy server URL? What could be the recommended way to do this - I thought the filter was the best choice, but was not 100% sure?

- , Glassfish , , .

+3
4

, , . , .

Filter doFilter. HttpServletResponseWrapper, .

Apache reverse-proxy x-forwarded-host HTTP ( , ). , , , - . , , .

/*
 * Replace the server URL with the proxy server URL when called from a proxy server 
 */
@Override
public void doFilter(
    ServletRequest request, 
    ServletResponse response,
    FilterChain filterChain) throws IOException, ServletException 
{
    WsdlResponseWrapper myResponse = new WsdlResponseWrapper((HttpServletResponse) response);
    filterChain.doFilter(request, myResponse);
    boolean isResponseOutputStream = myResponse.getOutputStreamContent().length > 0;

    /*
     * The servlet response sent into this method only allows access to
     * getOutputStream or getWriter, not both. It will throw an
     * exception if an attempt is made to to access both.
     * 
     * If this reason, I'm checking the output stream first and writing
     * that content if it exists, then printing to the writer only if
     * the output stream is empty.
     */
    StringBuffer responseBuffer;
    if (isResponseOutputStream) {
         responseBuffer = new StringBuffer(new String(myResponse.getOutputStreamContent()));
    } else {
        responseBuffer = new StringBuffer(myResponse.getWriterContent());
    }

    // Change the URL when called from a proxy server
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        String requestedHostname = httpServletRequest.getHeader("x-forwarded-host");
        if ((null != requestedHostname) && !requestedHostname.isEmpty()) {
            String myHostname = httpServletRequest.getHeader("host");
            int myPort = httpServletRequest.getLocalPort();

            // change the hostname
            int index = responseBuffer.indexOf(myHostname);
            int length = myHostname.length();
            while (index > -1) {
                responseBuffer.replace(index, index+length, requestedHostname);
                index = responseBuffer.indexOf(myHostname);
            }

            // remove the port
            String portString = ":" + myPort;
            length = portString.length();
            index = responseBuffer.indexOf(portString);
            while (index > -1) {
                responseBuffer.replace(index, index+length, "");
                index = responseBuffer.indexOf(portString);
            }
        }
    }

    // forward the response
    if (isResponseOutputStream) {
        response.getOutputStream().write(responseBuffer.toString().getBytes());
    } else {
        response.getWriter().print(responseBuffer);
    }
}
+1

Javaboutique -

public final class TimerFilter implements Filter 
{

  public void doFilter(ServletRequest request, 
                      ServletResponse response,
                      FilterChain chain)
     throws IOException, ServletException 
 {

     long startTime = System.currentTimeMillis();
     chain.doFilter(request, response);
     long stopTime = System.currentTimeMillis();
     System.out.println("Time to execute request: " + (stopTime - startTime) + 
         " milliseconds");

 }
...

chain.doFilter ( , @WebService API ), -, .

+1

- ?

glassfish doc - :

, Load Balancer, SSL. - , WSDL , , WSDL .

.

, : Glassfish ws management, aobut, .

, , , , , - .

+1

If Apache is your proxy server, you can try to do what I did, which is very simple. Apache is causing the problem (sorting), so use Apache to fix it:

fooobar.com/questions/1039004 / ...

0
source

All Articles