All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glassfish.webservices.monitoring.WebServiceTesterServlet Maven / Gradle / Ivy

There is a newer version: 6.2024.6
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2014 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
 * https://glassfish.dev.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.
 */
// Portions Copyright 2018-2022 Payara Foundation and/or its affiliates
/*
 * WebServiceTesterServlet.java
 *
 * Created on August 6, 2004, 9:14 AM
 */

package org.glassfish.webservices.monitoring;

import com.sun.enterprise.deployment.WebServiceEndpoint;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.tools.ws.spi.WSToolsObjectFactory;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.xml.ws.Service;
import jakarta.xml.ws.WebEndpoint;
import org.glassfish.jaxb.runtime.api.JAXBRIContext;
import org.glassfish.webservices.LogUtils;

import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * This servlet is responsible for testing web-services.
 *
 * @author Jerome Dochez
 */
public class WebServiceTesterServlet extends HttpServlet {

    private static final Logger logger = LogUtils.getLogger();
    private static final long serialVersionUID = -5744091836362541633L;
    private final WebServiceEndpoint svcEP;


    private static final Hashtable gsiClasses = new Hashtable();
    private static final Hashtable ports = new Hashtable();
    // resources...
    private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(WebServiceTesterServlet.class);

    public static void invoke(HttpServletRequest request, HttpServletResponse response, WebServiceEndpoint endpoint) {

        try {
            WebServiceTesterServlet servlet = new WebServiceTesterServlet(endpoint);

            response.setCharacterEncoding("UTF-8");

            // Validate Host Header to help prevent Host Header Attacks
            if (!servlet.isValidHostHeader(request)) {
                throw new ServletException("Host Header does not appear to be valid - it does not appear to be a " +
                        "valid IPv6 literal, IPv4 dotted-decimal, or DNS name.");
            }

            if (request.getMethod().equalsIgnoreCase("GET")) {
                servlet.doGet(request, response);
            } else {
                servlet.doPost(request, response);
            }
        } catch (Exception e) {
            try (PrintWriter out = response.getWriter()){
                out.print("" + localStrings
                                .getLocalString("enterprise.webservice.monitoring.methodInvocationException", "Method invocation exception")
                        + "");
                out.print("

" + localStrings.getLocalString("enterprise.webservice.monitoring.ExceptionDetails", "Exceptions details : {0}", new Object[] { e.getMessage() }) + "

"); out.print("
"); e.printStackTrace(out); out.print("
"); out.print(""); } catch (Exception ex) { } } } /** * Creates a new instance of WebServiceTesterServlet * * @param ep endpoint to monitor */ public WebServiceTesterServlet(WebServiceEndpoint ep) { svcEP = ep; } @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); res.setHeader("pragma", "no-cache"); PrintWriter out = res.getWriter(); String requestURL = req.getRequestURL().toString(); Endpoint myEndpoint; if (svcEP.implementedByWebComponent()) { myEndpoint = WebServiceEngineImpl.getInstance().getEndpoint(req.getServletPath()); } else { myEndpoint = WebServiceEngineImpl.getInstance().getEndpoint(req.getRequestURI()); } String seiClassName = myEndpoint.getDescriptor().getServiceEndpointInterface(); ClassLoader testerCL = svcEP.getWebService().getBundleDescriptor().getClassLoader(); if (testerCL != null) { Thread.currentThread().setContextClassLoader(testerCL); } // For now support Tester servlet for JAXWS based services only try { Class seiClass = Thread.currentThread().getContextClassLoader().loadClass(seiClassName); if (seiClass.getAnnotation(jakarta.jws.WebService.class) == null) { testerNotSupportedError(myEndpoint.getDescriptor().getServiceName(), out); return; } } catch (ClassNotFoundException clnfEx) { classNotAccessibleError(Thread.currentThread().getContextClassLoader(), seiClassName, out); return; } initializePort(req, res); Class clientSEI = gsiClasses.get(requestURL); out.print("" + myEndpoint.getDescriptor().getServiceName().getLocalPart() + " " + localStrings.getLocalString("enterprise.webservice.monitoring.title", "Web Service Tester") + ""); out.print("

" + myEndpoint.getDescriptor().getServiceName().getLocalPart() + " " + localStrings.getLocalString("enterprise.webservice.monitoring.title", "Web Service Tester") + "

"); // Microsoft Internet Explorer does not handle




© 2015 - 2024 Weber Informatics LLC | Privacy Policy