javax.jws.HandlerChain Java Examples

The following examples show how to use javax.jws.HandlerChain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsDeployer.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static HandlerChains getHandlerChains(Class<?> declaringClass, final String serviceEndpoint, final ClassLoader classLoader) throws OpenEJBException {
    HandlerChain handlerChain = declaringClass.getAnnotation(HandlerChain.class);
    if (handlerChain == null && serviceEndpoint != null) {
        try {
            declaringClass = classLoader.loadClass(serviceEndpoint);
            handlerChain = declaringClass.getAnnotation(HandlerChain.class);
        } catch (final ClassNotFoundException ignored) {
            // no-op
        }
    }
    HandlerChains handlerChains = null;
    if (handlerChain != null) {
        try {
            final URL handlerFileURL = declaringClass.getResource(handlerChain.file());
            handlerChains = ReadDescriptors.readHandlerChains(handlerFileURL);
        } catch (final Throwable e) {
            throw new OpenEJBException("Unable to load handler chain file: " + handlerChain.file(), e);
        }
    }
    return handlerChains;
}
 
Example #2
Source File: HandlerAnnotationProcessor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #3
Source File: HandlerAnnotationProcessor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #4
Source File: HandlerConfigGenerator.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void generate(ToolContext penv) throws ToolException {
    this.env = penv;

    if (passthrough()) {
        return;
    }

    Element e = this.intf.getHandlerChains();
    List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(e,
                                                                 ToolConstants.HANDLER_CHAINS_URI,
                                                                 ToolConstants.HANDLER_CHAIN);
    if (!elemList.isEmpty()) {
        String fName = ProcessorUtil.getHandlerConfigFileName(this.intf.getName());
        handlerChainAnnotation = new JAnnotation(HandlerChain.class);
        handlerChainAnnotation.addElement(new JAnnotationElement("name",
                                                                 HANDLER_CHAIN_NAME));
        handlerChainAnnotation.addElement(new JAnnotationElement("file", fName + ".xml"));
        generateHandlerChainFile(e, parseOutputName(this.intf.getPackageName(),
                                                    fName,
                                                    ".xml"));
    }
}
 
Example #5
Source File: HandlerAnnotationProcessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #6
Source File: HandlerAnnotationProcessor.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    Package pkg = clazz.getPackage();
    String filename = chain.file();
    String fullpath = addPackagePath(filename, pkg);
    InputStream is;

    is = moduleResource(clazz, filename);
    if (is != null) return is;

    is = moduleResource(clazz, fullpath);
    if (is != null) return is;

    URL url = cpResource(clazz, filename);
    if (url == null) url = cpResource(clazz, fullpath);

    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
                clazz.getName(), filename);
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
                clazz.getName(), filename);
    }
}
 
Example #7
Source File: HandlerAnnotationProcessor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #8
Source File: HandlerAnnotationProcessor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #9
Source File: HandlerAnnotationProcessor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #10
Source File: HandlerAnnotationProcessor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static InputStream getFileAsStream(Class clazz, HandlerChain chain) {
    URL url = clazz.getResource(chain.file());
    if (url == null) {
        url = Thread.currentThread().getContextClassLoader().
            getResource(chain.file());
    }
    if (url == null) {
        String tmp = clazz.getPackage().getName();
        tmp = tmp.replace('.', '/');
        tmp += "/" + chain.file();
        url =
            Thread.currentThread().getContextClassLoader().getResource(tmp);
    }
    if (url == null) {
        throw new UtilException("util.failed.to.find.handlerchain.file",
            clazz.getName(), chain.file());
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new UtilException("util.failed.to.parse.handlerchain.file",
            clazz.getName(), chain.file());
    }
}
 
Example #11
Source File: GeneratorBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #12
Source File: CodeGenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWSAddress() throws Exception {
    env.addNamespacePackageMap("http://cxf.apache.org/w2j/hello_world_soap_http", "ws.address");
    env.put(ToolConstants.CFG_BINDING, getLocation("/wsdl2java_wsdl/ws_address_binding.wsdl"));
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_addr.wsdl"));

    processor.setContext(env);
    processor.execute();

    assertNotNull(output);

    File ws = new File(output, "ws");
    assertTrue(ws.exists());
    File address = new File(ws, "address");
    assertTrue(address.exists());

    File[] files = address.listFiles();
    assertEquals(Arrays.asList(address.listFiles()).toString(), 6, files.length);
    File handlerConfig = new File(address, "Greeter_handler.xml");
    assertTrue(handlerConfig.exists());

    Class<?> clz = classLoader.loadClass("ws.address.Greeter");
    HandlerChain handlerChainAnno = AnnotationUtil.getPrivClassAnnotation(clz, HandlerChain.class);
    assertEquals("Greeter_handler.xml", handlerChainAnno.file());
    assertNotNull("Handler chain xml generate fail!", classLoader
        .getResource("ws/address/Greeter_handler.xml"));
}
 
Example #13
Source File: GeneratorBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #14
Source File: GeneratorBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #15
Source File: GeneratorBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #16
Source File: GeneratorBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #17
Source File: GeneratorBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #18
Source File: GeneratorBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #19
Source File: GeneratorBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
    Element e = options.getHandlerChainConfiguration();
    if (e == null) {
        return;
    }
    JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
    NodeList nl = e.getElementsByTagNameNS(
        "http://java.sun.com/xml/ns/javaee", "handler-chain");
    if(nl.getLength() > 0){
        String fName = getHandlerConfigFileName(className);
        handlerChainAnn.param("file", fName);
        generateHandlerChainFile(e, className);
    }
}
 
Example #20
Source File: SEIGenerator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }

    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>)penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {

        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();

        if (interfaces.isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            continue;
        }
        for (JavaInterface intf : interfaces.values()) {

            if (hasHandlerConfig(intf)) {
                HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
                // REVISIT: find a better way to handle Handler gen, should not
                // pass JavaInterface around.
                handlerGen.setJavaInterface(intf);
                handlerGen.generate(getEnvironment());

                JAnnotation annot = handlerGen.getHandlerAnnotation();
                if (handlerGen.getHandlerAnnotation() != null) {
                    boolean existHandlerAnno = false;
                    for (JAnnotation jann : intf.getAnnotations()) {
                        if (jann.getType() == HandlerChain.class) {
                            existHandlerAnno = true;
                        }
                    }
                    if (!existHandlerAnno) {
                        intf.addAnnotation(annot);
                        intf.addImport("javax.jws.HandlerChain");
                    }
                }
            }
            if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
                JAnnotation ann = new JAnnotation(DataBinding.class);
                JAnnotationElement el
                    = new JAnnotationElement(null,
                                             penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS),
                                             true);
                ann.addElement(el);
                intf.addAnnotation(ann);
            }
            clearAttributes();
            setAttributes("intf", intf);
            String seiSc = "";
            for (String s : intf.getSuperInterfaces()) {
                if (!seiSc.isEmpty()) {
                    seiSc += ", ";
                } else {
                    seiSc = "extends ";
                }
                seiSc += s;
            }
            if (!StringUtils.isEmpty(seiSc)) {
                seiSc += " ";
            }
            setAttributes("seiSuperinterfaceString", seiSc);
            setCommonAttributes();

            doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));

        }
    }
}
 
Example #21
Source File: AnnotationHandlerChainBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
private HandlerChainAnnotation findHandlerChainAnnotation(Class<?> clz, boolean searchSEI) {
    if (clz == null) {
        return null;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Checking for HandlerChain annotation on " + clz.getName());
    }
    HandlerChainAnnotation hcAnn = null;
    HandlerChain ann = clz.getAnnotation(HandlerChain.class);
    if (ann == null) {
        if (searchSEI) {
            /* HandlerChain annotation can be specified on the SEI
             * but the implementation bean might not implement the SEI.
             */
            WebService ws = clz.getAnnotation(WebService.class);
            if (ws != null && !StringUtils.isEmpty(ws.endpointInterface())) {
                String seiClassName = ws.endpointInterface().trim();
                Class<?> seiClass = null;
                try {
                    seiClass = ClassLoaderUtils.loadClass(seiClassName, clz);
                } catch (ClassNotFoundException e) {
                    throw new WebServiceException(BUNDLE.getString("SEI_LOAD_FAILURE_EXC"), e);
                }

                // check SEI class and its interfaces for HandlerChain annotation
                hcAnn = findHandlerChainAnnotation(seiClass, false);
            }
        }
        if (hcAnn == null) {
            // check interfaces for HandlerChain annotation
            for (Class<?> iface : clz.getInterfaces()) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("Checking for HandlerChain annotation on " + iface.getName());
                }
                ann = iface.getAnnotation(HandlerChain.class);
                if (ann != null) {
                    hcAnn = new HandlerChainAnnotation(ann, iface);
                    break;
                }
            }
            if (hcAnn == null) {
                hcAnn = findHandlerChainAnnotation(clz.getSuperclass(), false);
            }
        }
    } else {
        hcAnn = new HandlerChainAnnotation(ann, clz);
    }

    return hcAnn;
}
 
Example #22
Source File: AnnotationHandlerChainBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
HandlerChainAnnotation(HandlerChain hc, Class<?> clz) {
    ann = hc;
    declaringClass = clz;
}