use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.
the class WSServiceDelegate method getWSDLModelfromSEI.
private WSDLService getWSDLModelfromSEI(final Class sei) {
WebService ws = AccessController.doPrivileged(new PrivilegedAction<>() {
public WebService run() {
return (WebService) sei.getAnnotation(WebService.class);
}
});
if (ws == null || ws.wsdlLocation().equals(""))
return null;
String wsdlLocation = ws.wsdlLocation();
wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
Source wsdl = new StreamSource(wsdlLocation);
WSDLService service = null;
try {
URL url = wsdl.getSystemId() == null ? null : new URL(wsdl.getSystemId());
WSDLModel model = parseWSDL(url, wsdl, sei);
service = model.getService(this.serviceName);
if (service == null)
throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME(this.serviceName, buildNameList(model.getServices().keySet())));
} catch (MalformedURLException e) {
throw new WebServiceException(ClientMessages.INVALID_WSDL_URL(wsdl.getSystemId()));
}
return service;
}
use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.
the class SDODatabindingTestBase method invmSetup.
protected WebServiceFeature[] invmSetup(final URL wsdlURL, final Class sei, final Class seb, final QName serviceName, final QName portName) {
DatabindingModeFeature dbmf = new DatabindingModeFeature("eclipselink.sdo");
Class implementorClass = seb;
boolean handlersSetInDD = false;
Container container = Container.NONE;
Map<String, SDDocumentSource> docs = new HashMap<String, SDDocumentSource>();
SDDocumentSource primaryWSDL = SDDocumentSource.create(wsdlURL);
docs.put(wsdlURL.toString(), primaryWSDL);
ExternalMetadataFeature exm = ExternalMetadataFeature.builder().setReader(new com.sun.xml.ws.model.ReflectAnnotationReader() {
public <A extends Annotation> A getAnnotation(final Class<A> annType, final Class<?> cls) {
if (WebService.class.equals(annType)) {
final WebService ws = cls.getAnnotation(WebService.class);
return (A) new jakarta.jws.WebService() {
public Class<? extends Annotation> annotationType() {
return WebService.class;
}
@Override
public String endpointInterface() {
return sei.getName();
}
@Override
public String name() {
return (ws != null) ? ws.name() : null;
}
@Override
public String portName() {
return (ws != null) ? ws.portName() : null;
}
@Override
public String serviceName() {
return (ws != null) ? ws.serviceName() : null;
}
@Override
public String targetNamespace() {
return (ws != null) ? ws.targetNamespace() : null;
}
@Override
public String wsdlLocation() {
return (ws != null) ? ws.wsdlLocation() : null;
}
};
}
return cls.getAnnotation(annType);
}
}).build();
BindingID bindingID = BindingID.parse(implementorClass);
WSBinding binding = bindingID.createBinding(dbmf, exm);
final WSEndpoint<?> endpoint = WSEndpoint.create(implementorClass, !handlersSetInDD, null, serviceName, portName, container, binding, primaryWSDL, docs.values(), XmlUtil.createEntityResolver(null), false);
ComponentFeature cf = new ComponentFeature(new com.sun.xml.ws.api.Component() {
public <S> S getSPI(Class<S> spiType) {
if (TransportTubeFactory.class.equals(spiType))
return (S) new TransportTubeFactory() {
public Tube doCreate(ClientTubeAssemblerContext context) {
return new InVmTransportTube(context.getCodec(), context.getBinding(), wsdlURL, endpoint);
}
};
return null;
}
});
WebServiceFeature[] f = { dbmf, cf };
return f;
}
use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.
the class EndpointFactory method verifyImplementorClass.
/**
* Verifies if the endpoint implementor class has @WebService or @WebServiceProvider
* annotation; passing MetadataReader instance allows to read annotations from
* xml descriptor instead of class's annotations
*
* @return
* true if it is a Provider or AsyncProvider endpoint
* false otherwise
* @throws java.lang.IllegalArgumentException
* If it doesn't have any one of @WebService or @WebServiceProvider
* If it has both @WebService and @WebServiceProvider annotations
*/
public static boolean verifyImplementorClass(Class<?> clz, MetadataReader metadataReader) {
if (metadataReader == null) {
metadataReader = new ReflectAnnotationReader();
}
WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, clz);
WebService ws = metadataReader.getAnnotation(WebService.class, clz);
if (wsProvider == null && ws == null) {
throw new IllegalArgumentException(clz + " has neither @WebService nor @WebServiceProvider annotation");
}
if (wsProvider != null && ws != null) {
throw new IllegalArgumentException(clz + " has both @WebService and @WebServiceProvider annotations");
}
if (wsProvider != null) {
if (Provider.class.isAssignableFrom(clz) || AsyncProvider.class.isAssignableFrom(clz)) {
return true;
}
throw new IllegalArgumentException(clz + " doesn't implement Provider or AsyncProvider interface");
}
return false;
}
use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.
the class HandlerAnnotationProcessor method getSEI.
static Class getSEI(Class<?> clazz, MetadataReader metadataReader) {
if (metadataReader == null) {
metadataReader = new ReflectAnnotationReader();
}
if (Provider.class.isAssignableFrom(clazz) || AsyncProvider.class.isAssignableFrom(clazz)) {
// No SEI for Provider Implementation
return null;
}
if (Service.class.isAssignableFrom(clazz)) {
// No SEI for Service class
return null;
}
WebService webService = metadataReader.getAnnotation(WebService.class, clazz);
if (webService == null) {
throw new UtilException("util.handler.no.webservice.annotation", clazz.getCanonicalName());
}
String ei = webService.endpointInterface();
if (ei.length() > 0) {
clazz = getClass(webService.endpointInterface());
WebService ws = metadataReader.getAnnotation(WebService.class, clazz);
if (ws == null) {
throw new UtilException("util.handler.endpoint.interface.no.webservice", webService.endpointInterface());
}
return clazz;
}
return null;
}
use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.
the class SeiGenerator method write.
private void write(Port port) {
JavaInterface intf = port.getJavaInterface();
String className = Names.customJavaTypeClassName(intf);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls;
try {
cls = getClass(className, ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
QName portTypeName = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
Locator loc = null;
if (portTypeName != null) {
PortType pt = port.portTypes.get(portTypeName);
if (pt != null) {
loc = pt.getLocator();
}
}
receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
return;
}
// so skip it.
if (!cls.methods().isEmpty()) {
return;
}
// write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
String ptDoc = intf.getJavaDoc();
if (ptDoc != null) {
comment.add(ptDoc);
comment.add("\n\n");
}
comment.addAll(getJAXWSClassComment());
// @WebService
JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
writeWebServiceAnnotation(port, webServiceAnn);
// @HandlerChain
writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options);
// @SOAPBinding
writeSOAPBinding(port, cls);
// @XmlSeeAlso
if (options.target.isLaterThan(Options.Target.V2_1)) {
writeXmlSeeAlso(cls);
}
for (Operation operation : port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
// @WebMethod
JMethod m;
JDocComment methodDoc;
String methodJavaDoc = operation.getJavaDoc();
if (method.getReturnType().getName().equals("void")) {
m = cls.method(JMod.PUBLIC, void.class, method.getName());
methodDoc = m.javadoc();
} else {
JAXBTypeAndAnnotation retType = method.getReturnType().getType();
m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
retType.annotate(m);
methodDoc = m.javadoc();
JCommentPart ret = methodDoc.addReturn();
ret.add("returns " + retType.getName());
}
if (methodJavaDoc != null) {
methodDoc.add(methodJavaDoc);
}
writeWebMethod(operation, m);
JClass holder = cm.ref(Holder.class);
for (JavaParameter parameter : method.getParametersList()) {
JVar var;
JAXBTypeAndAnnotation paramType = parameter.getType().getType();
if (parameter.isHolder()) {
var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
} else {
var = m.param(paramType.getType(), parameter.getName());
}
// annotate parameter with JAXB annotations
paramType.annotate(var);
methodDoc.addParam(var);
JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class));
writeWebParam(operation, parameter, paramAnn);
}
com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
for (Fault fault : operation.getFaultsSet()) {
m._throws(fault.getExceptionClass());
methodDoc.addThrows(fault.getExceptionClass());
wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
}
// It should be the last thing to invoke after JMethod is built completely
extension.writeMethodAnnotations(wsdlOp, m);
}
}
Aggregations