Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * http://glassfish.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.xml.ws.transport.httpspi.servlet;
 
 import java.util.List;
 import java.util.Map;
Called by WSSPIServlet to choose EndpointAdapter and sends a request to it.

One instance of this object is created, and then shared across WSSPIServlet instances (the container might deploy many of them, depending on how the user writes web.xml.)

Author(s):
Jitendra Kotamraju
 
 public class WSServletDelegate {

    
All EndpointAdapters that are deployed in the current web application.
 
     public final List<EndpointAdapteradapters;
 
 
     public WSServletDelegate(List<EndpointAdapteradaptersServletContext context) {
         this. = adapters;
 
         for(EndpointAdapter info : adapters) {
             registerEndpointUrlPattern(info);
         }
 
         if (.isLoggable(.)) {
             .log(."Initializing Servlet for {0}");
         }
 
     }
 
     public void destroy() {
         if (.isLoggable(.)) {
             .log(."Destroying Servlet for {0}");
         }
 
         for(EndpointAdapter a : ) {
             try {
                 a.dispose();
            } catch(Throwable e) {
                .log(.e.getMessage(), e);
            }
        }
    }
    public void doGet(HttpServletRequest requestHttpServletResponse responseServletContext context) {
        try {
            EndpointAdapter target = getTarget(request);
            if (target != null) {
                if (.isLoggable(.)) {
                    .log(."Got request for endpoint {0}"target.getUrlPattern());
                }
                target.handle(contextrequestresponse);
            } else {
                writeNotFoundErrorPage(response"Invalid Request");
            }
        } catch (WebServiceException e) {
            .log(.e.getLocalizedMessage(), e);
            response.setStatus(.);
        } catch (Throwable e) {
            .log(."caught throwable"e);
            response.setStatus(.);
        }
    }

    
processes web service requests by finding the EndpointAdapter created by the WSSPIContextListener

Parameters:
request the HTTP request object
response the HTTP response object
context servlet context
    public void doPost(HttpServletRequest requestHttpServletResponse responseServletContext context) {
        doGet(requestresponse,context);
    }

    
Handles HTTP PUT for XML/HTTP binding based endpoints

Parameters:
request the HTTP request object
response the HTTP response object
context servlet context
    public void doPut(HttpServletRequest requestHttpServletResponse responseServletContext context) {
        // TODO: unify this into doGet.
        try {
            EndpointAdapter target = getTarget(request);
            if (target != null) {
                if (.isLoggable(.)) {
                    .log(."Got request for endpoint {0}"target.getUrlPattern());
                }
            } else {
                writeNotFoundErrorPage(response"Invalid request");
                return;
            }
            Binding binding = target.getEndpoint().getBinding();
            if (binding instanceof HTTPBinding) {
                target.handle(contextrequestresponse);
            } else {
                response.setStatus(.);
            }
        } catch (WebServiceException e) {
            .log(.e.getLocalizedMessage(), e);
            response.setStatus(.);
        } catch (Throwable e) {
            .log(."caught throwable"e);
            response.setStatus(.);
            response.setStatus(.);
        }
    }


    
Handles HTTP DELETE for XML/HTTP binding based endpoints

Parameters:
request the HTTP request object
response the HTTP response object
context servlet context
    public void doDelete(HttpServletRequest requestHttpServletResponse responseServletContext context) {
        // At preseent, there is no difference for between PUT and DELETE processing
        doPut(requestresponsecontext);
    }
    private void writeNotFoundErrorPage(
        HttpServletResponse response,
        String message)
        throws IOException {
        response.setStatus(.);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>");
        out.println("Web Services");
        out.println("</title></head>");
        out.println("<body>");
        out.println("Not found "+message);
        out.println("</body>");
        out.println("</html>");
    }
    private void registerEndpointUrlPattern(EndpointAdapter a) {
        String urlPattern = a.getUrlPattern();
        if (urlPattern.indexOf("*.") != -1) {
            // cannot deal with implicit mapping right now
            .log(."Ignoring implicit url-pattern {0}"urlPattern);
        } else if (urlPattern.endsWith("/*")) {
            .add(a);
        } else {
            if (.containsKey(urlPattern)) {
                .log(."Ignoring duplicate url-pattern {0}"urlPattern);
            } else {
                .put(urlPatterna);
            }
        }
    }

    
Determines which EndpointAdapter serves the given request.

Parameters:
request the HTTP request object
    protected EndpointAdapter getTarget(HttpServletRequest request) {
        String path =
            request.getRequestURI().substring(
                request.getContextPath().length());
        EndpointAdapter result = .get(path);
        if (result == null) {
            for (EndpointAdapter candidate : ) {
                String noSlashStar = candidate.getValidPath();
                if (path.equals(noSlashStar) || path.startsWith(noSlashStar+"/") || path.startsWith(noSlashStar+"?")) {
                    result = candidate;
                    break;
                }
            }
        }
        return result;
    }
    private static final Logger logger =
        Logger.getLogger(WSServletDelegate.class.getName());
New to GrepCode? Check out our FAQ X