jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/util/HandlerAnnotationProcessor.java
author alanb
Thu, 17 Mar 2016 19:04:08 +0000
changeset 36523 116e5d5cdade
parent 25871 b80b84e87032
child 44560 7ecd9d2e2a6e
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: lancea, mchung Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, miroslav.kos@oracle.com, erik.joelsson@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     1
/*
36523
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     4
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    10
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    15
 * accompanied this code).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    16
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    20
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    23
 * questions.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    24
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    25
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    26
package com.sun.xml.internal.ws.util;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    27
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    28
import com.sun.xml.internal.ws.api.WSBinding;
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    29
import com.sun.xml.internal.ws.api.databinding.MetadataReader;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    30
import com.sun.xml.internal.ws.api.server.AsyncProvider;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    31
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    32
import com.sun.xml.internal.ws.handler.HandlerChainsModel;
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    33
import com.sun.xml.internal.ws.model.ReflectAnnotationReader;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    34
import com.sun.xml.internal.ws.server.EndpointFactory;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    35
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    36
import com.sun.istack.internal.NotNull;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    37
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    38
import javax.jws.HandlerChain;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    39
import javax.jws.WebService;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    40
import javax.jws.soap.SOAPMessageHandlers;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    41
import javax.xml.namespace.QName;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    42
import javax.xml.stream.XMLStreamException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    43
import javax.xml.stream.XMLStreamReader;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    44
import javax.xml.ws.Provider;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    45
import javax.xml.ws.Service;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    46
import java.io.IOException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    47
import java.io.InputStream;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    48
import java.net.URL;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    49
import java.util.logging.Logger;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    50
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    51
/**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    52
 * <p>Used by client and server side to create handler information
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    53
 * from annotated class. The public methods all return a
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    54
 * HandlerChainInfo that contains the handlers and role information
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    55
 * needed at runtime.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    56
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    57
 * <p>All of the handler chain descriptors follow the same schema,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    58
 * whether they are wsdl customizations, handler files specified
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    59
 * by an annotation, or are included in the sun-jaxws.xml file.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    60
 * So this class is used for all handler xml information. The
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    61
 * two public entry points are
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    62
 * {@link HandlerAnnotationProcessor#buildHandlerInfo}, called
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    63
 * when you have an annotated class that points to a file.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    64
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    65
 * <p>The methods in the class are static so that it may called
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    66
 * from the runtime statically.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    67
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    68
 * @see com.sun.xml.internal.ws.util.HandlerAnnotationInfo
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    69
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    70
 * @author JAX-WS Development Team
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    71
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    72
public class HandlerAnnotationProcessor {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    73
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    74
    private static final Logger logger = Logger.getLogger(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    75
        com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".util");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    76
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    77
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    78
     * <p>This method is called by
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    79
     * {@link EndpointFactory} when
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    80
     * they have an annotated class.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    81
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    82
     * <p>If there is no handler chain annotation on the class,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    83
     * this method will return null. Otherwise it will load the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    84
     * class and call the parseHandlerFile method to read the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    85
     * information.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    86
     *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    87
     * @return A HandlerAnnotationInfo object that stores the
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    88
     * handlers and roles. Will return null if the class passed
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    89
     * in has no handler chain annotation.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    90
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    91
    public static HandlerAnnotationInfo buildHandlerInfo(@NotNull
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    92
        Class<?> clazz, QName serviceName, QName portName, WSBinding binding) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    93
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    94
        MetadataReader metadataReader = EndpointFactory.getExternalMetadatReader(clazz, binding);
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    95
        if (metadataReader == null) {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    96
            metadataReader = new ReflectAnnotationReader();
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    97
        }
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    98
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    99
//        clazz = checkClass(clazz);
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   100
        HandlerChain handlerChain = metadataReader.getAnnotation(HandlerChain.class, clazz);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   101
        if (handlerChain == null) {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   102
            clazz = getSEI(clazz, metadataReader);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   103
            if (clazz != null)
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   104
            handlerChain = metadataReader.getAnnotation(HandlerChain.class, clazz);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   105
            if (handlerChain == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   106
                return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   107
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   108
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   109
        if (clazz.getAnnotation(SOAPMessageHandlers.class) != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   110
            throw new UtilException(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   111
                "util.handler.cannot.combine.soapmessagehandlers");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   112
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   113
        InputStream iStream = getFileAsStream(clazz, handlerChain);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   114
        XMLStreamReader reader =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   115
            XMLStreamReaderFactory.create(null,iStream, true);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   116
        XMLStreamReaderUtil.nextElementContent(reader);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   117
        HandlerAnnotationInfo handlerAnnInfo = HandlerChainsModel.parseHandlerFile(reader, clazz.getClassLoader(),
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   118
            serviceName, portName, binding);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   119
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   120
            reader.close();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   121
            iStream.close();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   122
        } catch (XMLStreamException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   123
            e.printStackTrace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   124
            throw new UtilException(e.getMessage());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   125
        } catch (IOException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   126
            e.printStackTrace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   127
            throw new UtilException(e.getMessage());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   128
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   129
        return handlerAnnInfo;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   130
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   131
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   132
    public static HandlerChainsModel buildHandlerChainsModel(final Class<?> clazz) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   133
        if(clazz == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   134
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   135
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   136
        HandlerChain handlerChain =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   137
            clazz.getAnnotation(HandlerChain.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   138
        if(handlerChain == null)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   139
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   140
        InputStream iStream = getFileAsStream(clazz, handlerChain);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   141
        XMLStreamReader reader =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   142
            XMLStreamReaderFactory.create(null,iStream, true);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   143
        XMLStreamReaderUtil.nextElementContent(reader);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   144
        HandlerChainsModel handlerChainsModel = HandlerChainsModel.parseHandlerConfigFile(clazz, reader);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   145
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   146
            reader.close();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   147
            iStream.close();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   148
        } catch (XMLStreamException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   149
            e.printStackTrace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   150
            throw new UtilException(e.getMessage());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   151
        } catch (IOException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   152
            e.printStackTrace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   153
            throw new UtilException(e.getMessage());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   154
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   155
        return handlerChainsModel;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   156
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   157
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   158
    static Class getClass(String className) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   159
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   160
            return Thread.currentThread().getContextClassLoader().loadClass(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   161
                className);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   162
        } catch (ClassNotFoundException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   163
            throw new UtilException("util.handler.class.not.found",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   164
                className);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   165
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   166
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   167
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   168
    static Class getSEI(Class<?> clazz, MetadataReader metadataReader) {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   169
        if (metadataReader == null) {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   170
            metadataReader = new ReflectAnnotationReader();
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   171
        }
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   172
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   173
        if (Provider.class.isAssignableFrom(clazz) || AsyncProvider.class.isAssignableFrom(clazz)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   174
            //No SEI for Provider Implementation
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   175
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   176
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   177
        if (Service.class.isAssignableFrom(clazz)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   178
            //No SEI for Service class
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   179
            return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   180
        }
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   181
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   182
        WebService webService = metadataReader.getAnnotation(WebService.class, clazz);
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   183
        if (webService == null) {
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   184
            throw new UtilException("util.handler.no.webservice.annotation", clazz.getCanonicalName());
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   185
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   186
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   187
        String ei = webService.endpointInterface();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   188
        if (ei.length() > 0) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   189
            clazz = getClass(webService.endpointInterface());
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   190
            WebService ws = metadataReader.getAnnotation(WebService.class, clazz);
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   191
            if (ws == null) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   192
                throw new UtilException("util.handler.endpoint.interface.no.webservice",
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   193
                    webService.endpointInterface());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   194
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   195
            return clazz;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   196
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   197
        return null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   198
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   199
36523
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   200
    static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   201
        Package pkg = clazz.getPackage();
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   202
        String filename = chain.file();
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   203
        String fullpath = addPackagePath(filename, pkg);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   204
        InputStream is;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   205
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   206
        is = moduleResource(clazz, filename);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   207
        if (is != null) return is;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   208
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   209
        is = moduleResource(clazz, fullpath);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   210
        if (is != null) return is;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   211
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   212
        URL url = cpResource(clazz, filename);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   213
        if (url == null) url = cpResource(clazz, fullpath);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   214
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   215
        if (url == null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   216
            throw new UtilException("util.failed.to.find.handlerchain.file",
36523
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   217
                    clazz.getName(), filename);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   218
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   219
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   220
            return url.openStream();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   221
        } catch (IOException e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   222
            throw new UtilException("util.failed.to.parse.handlerchain.file",
36523
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   223
                    clazz.getName(), filename);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   224
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   225
    }
36523
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   226
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   227
    private static URL cpResource(Class clazz, String name) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   228
        URL url = clazz.getResource(name);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   229
        if (url == null) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   230
            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   231
            url = tccl.getResource(name);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   232
        }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   233
        return url;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   234
    }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   235
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   236
    private static InputStream moduleResource(Class resolvingClass, String name) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   237
        java.lang.reflect.Module module = resolvingClass.getModule();
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   238
        if (module != null) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   239
            try {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   240
                InputStream stream = module.getResourceAsStream(name);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   241
                if (stream != null) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   242
                    return stream;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   243
                }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   244
            } catch(IOException e) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   245
                throw new UtilException("util.failed.to.find.handlerchain.file",
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   246
                        resolvingClass.getName(), name);
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   247
            }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   248
        }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   249
        return null;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   250
    }
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   251
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   252
    private static String addPackagePath(String file, Package pkg) {
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   253
        String tmp = pkg.getName();
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   254
        tmp = tmp.replace('.', '/');
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   255
        tmp += "/" + file;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   256
        return tmp;
116e5d5cdade 8142968: Module System implementation
alanb
parents: 25871
diff changeset
   257
    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   258
}