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()); } }
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); } }
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; }
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); } }
/** * This method is use to attach @HandlerChain annotation data to a composite object. * * @param composite - <code>TMFAnnotationComposite</code> * @param annotatedElement - <code>AnnotatedElement</code> */ public static void attachHandlerChainAnnotation(TMFAnnotationComposite composite, AnnotatedElement annotatedElement) { HandlerChain handlerChain = (HandlerChain)ConverterUtils.getAnnotation( HandlerChain.class, annotatedElement); if (handlerChain != null) { HandlerChainAnnot hcAnnot = ConverterUtils.createHandlerChainAnnot( handlerChain); composite.setHandlerChainAnnot(hcAnnot); } }
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); } }
/** * Scan for @EJB, @Resource, @WebServiceRef, @PersistenceUnit, and @PersistenceContext on WebService HandlerChain classes */ private void processWebServiceHandlers(final EjbModule ejbModule, final EnterpriseBean bean, final AnnotationFinder finder) throws OpenEJBException { // add webservice handler classes to the class finder used in annotation processing final Set<String> classes = new HashSet<>(); if (ejbModule.getWebservices() != null) { for (final WebserviceDescription webservice : ejbModule.getWebservices().getWebserviceDescription()) { for (final PortComponent port : webservice.getPortComponent()) { // only process port definitions for this ejb if (!bean.getEjbName().equals(port.getServiceImplBean().getEjbLink())) { continue; } if (port.getHandlerChains() == null) { continue; } for (final org.apache.openejb.jee.HandlerChain handlerChain : port.getHandlerChains().getHandlerChain()) { for (final Handler handler : handlerChain.getHandler()) { final String handlerClass = realClassName(handler.getHandlerClass()); if (handlerClass != null) { classes.add(handlerClass); } } } } } } // classes.add(bean.getEjbClass()); final AnnotationFinder handlersFinder = finder.select(classes); buildAnnotatedRefs(bean, handlersFinder, ejbModule.getClassLoader()); }
public HandlerChain getAnnoHandlerChainAnnotation(Object sparseCompositeKey) { if (this.handlerChainAnnotation == null) { if (composite.isServiceProvider()) { /* * Per JSR-181 The @HandlerChain annotation MAY be present on * the endpoint interface and service implementation bean. The * service implementations bean's @HandlerChain is used if * @HandlerChain is present on both. So, if we do find the * annotation on this impl, then don't worry about else * Otherwise, check to see if the SEI might be annotated with * @HandlerChain */ handlerChainAnnotation = composite.getHandlerChainAnnot(); if (handlerChainAnnotation == null) { // If this is NOT an implicit SEI, then check for the // annotation on the SEI if (!DescriptionUtils.isEmpty(getAnnoWebServiceEndpointInterface())) { DescriptionBuilderComposite seic = getServiceDescriptionImpl().getDBCMap() .get(composite.getWebServiceAnnot().endpointInterface()); if (seic != null) { handlerChainAnnotation = seic.getHandlerChainAnnot(); } } } } else { handlerChainAnnotation = composite.getHandlerChainAnnot(); } } if (handlerChainAnnotation == null) { if (sparseCompositeKey != null) { DescriptionBuilderComposite sparseComposite = composite.getSparseComposite(sparseCompositeKey); if (sparseComposite != null && sparseComposite.getHandlerChainAnnot() != null) { handlerChainAnnotation = sparseComposite.getHandlerChainAnnot(); } } } return handlerChainAnnotation; }
/** * @param serviceClass * Either {@link Service}.class or other generated service-derived classes. */ public WSServiceDelegate(@Nullable Source wsdl, @NotNull QName serviceName, @NotNull final Class<? extends Service> serviceClass) { //we cant create a Service without serviceName if (serviceName == null) throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME_NULL(serviceName)); InitParams initParams = INIT_PARAMS.get(); INIT_PARAMS.set(null); // mark it as consumed if(initParams==null) initParams = EMPTY_PARAMS; this.serviceName = serviceName; this.serviceClass = serviceClass; Container tContainer = initParams.getContainer()!=null ? initParams.getContainer() : ContainerResolver.getInstance().getContainer(); if (tContainer == Container.NONE) { tContainer = new ClientContainer(); } this.container = tContainer; // load interceptor ServiceInterceptor interceptor = ServiceInterceptorFactory.load(this, Thread.currentThread().getContextClassLoader()); ServiceInterceptor si = container.getSPI(ServiceInterceptor.class); if (si != null) { interceptor = ServiceInterceptor.aggregate(interceptor, si); } this.serviceInterceptor = interceptor; //if wsdl is null, try and get it from the WebServiceClient.wsdlLocation if(wsdl == null){ if(serviceClass != Service.class){ WebServiceClient wsClient = AccessController.doPrivileged(new PrivilegedAction<WebServiceClient>() { public WebServiceClient run() { return serviceClass.getAnnotation(WebServiceClient.class); } }); String wsdlLocation = wsClient.wsdlLocation(); wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation)); wsdl = new StreamSource(wsdlLocation); } } WSDLServiceImpl service=null; if (wsdl != null) { try { URL url = wsdl.getSystemId()==null ? null : new URL(wsdl.getSystemId()); WSDLModelImpl model = parseWSDL(url, wsdl); service = model.getService(this.serviceName); if (service == null) throw new WebServiceException( ClientMessages.INVALID_SERVICE_NAME(this.serviceName, buildNameList(model.getServices().keySet()))); // fill in statically known ports for (WSDLPortImpl port : service.getPorts()) ports.put(port.getName(), new PortInfo(this, port)); } catch (MalformedURLException e) { throw new WebServiceException(ClientMessages.INVALID_WSDL_URL(wsdl.getSystemId())); } } this.wsdlService = service; if (serviceClass != Service.class) { //if @HandlerChain present, set HandlerResolver on service context HandlerChain handlerChain = AccessController.doPrivileged(new PrivilegedAction<HandlerChain>() { public HandlerChain run() { return serviceClass.getAnnotation(HandlerChain.class); } }); if (handlerChain != null) handlerConfigurator = new AnnotationConfigurator(this); } }
/** * Scan for @EJB, @Resource, @WebServiceRef, @PersistenceUnit, and @PersistenceContext on WebService HandlerChain classes * * @param consumer * @param classLoader * @throws OpenEJBException */ private void processWebServiceClientHandlers(final JndiConsumer consumer, final AnnotationFinder finder, final ClassLoader classLoader) throws OpenEJBException { if (SystemInstance.get().hasProperty("openejb.geronimo")) { return; } final Set<String> processedClasses = new HashSet<>(); final Set<String> handlerClasses = new HashSet<>(); do { // get unprocessed handler classes handlerClasses.clear(); for (final ServiceRef serviceRef : consumer.getServiceRef()) { final HandlerChains chains = serviceRef.getAllHandlers(); if (chains == null) { continue; } for (final org.apache.openejb.jee.HandlerChain handlerChain : chains.getHandlerChain()) { for (final Handler handler : handlerChain.getHandler()) { if (handler.getHandlerClass() != null) { handlerClasses.add(realClassName(handler.getHandlerClass())); } } } } handlerClasses.removeAll(processedClasses); if (handlerClasses.isEmpty()) { continue; } // process handler classes final AnnotationFinder handlerAnnotationFinder = finder != null ? finder.select(handlerClasses) : new FinderFactory.OpenEJBAnnotationFinder(new FinderFactory.DoLoadClassesArchive(classLoader, handlerClasses)); /* * @EJB * @Resource * @WebServiceRef * @PersistenceUnit * @PersistenceContext */ buildAnnotatedRefs(consumer, handlerAnnotationFinder, classLoader); processedClasses.addAll(handlerClasses); } while (!handlerClasses.isEmpty()); }
/** * This is a helper method to create a <code>HandlerChainAnnot</code> since the * * @param handlerChain - <code>HandlerChain</code> * @return - <code>HandlerChainAnnot</code> * @HandlerChain annotation may be present on a Type, Method, or Field. */ public static HandlerChainAnnot createHandlerChainAnnot(HandlerChain handlerChain) { HandlerChainAnnot hcAnnot = HandlerChainAnnot.createHandlerChainAnnotImpl(); hcAnnot.setFile(handlerChain.file()); hcAnnot.setName(handlerChain.name()); return hcAnnot; }