use of com.sun.xml.ws.api.server.SDDocumentSource in project Payara by payara.
the class WsUtil method addFileAndDecendents.
/*
* Add the File and wsdls and schemas imported by it to a list of metadata
* documents used to initialize an endpoint. Canonicalize the paths and check
* whether the documents have already been added to the list.
*/
private void addFileAndDecendents(File file, ArrayList<SDDocumentSource> cumulative) throws Exception {
try {
// JAX-WS has trouble with "..'s" in paths here
file = file.getCanonicalFile();
} catch (IOException e) {
// hope JAX-WS can deal with the original path
}
// make sure we have not processed this file before
URL id = file.toURL();
boolean alreadyProcessed = false;
for (SDDocumentSource source : cumulative) {
if ((id.toString()).equals(source.getSystemId().toString())) {
alreadyProcessed = true;
break;
}
}
if (!alreadyProcessed) {
cumulative.add(0, SDDocumentSource.create(id));
getWsdlsAndSchemas(file, cumulative);
}
}
use of com.sun.xml.ws.api.server.SDDocumentSource in project Payara by payara.
the class EjbRuntimeEndpointInfo method prepareInvocation.
public Object prepareInvocation(boolean doPreInvoke) throws Exception {
ComponentInvocation inv = null;
AdapterInvocationInfo adapterInvInfo = new AdapterInvocationInfo();
// init'ing jaxws is done here - this sequence is important
if (adapter == null) {
synchronized (this) {
if (adapter == null) {
try {
// Set webservice context here
// If the endpoint has a WebServiceContext with @Resource then
// that has to be used
EjbDescriptor ejbDesc = endpoint.getEjbComponentImpl();
Iterator<ResourceReferenceDescriptor> it = ejbDesc.getResourceReferenceDescriptors().iterator();
while (it.hasNext()) {
ResourceReferenceDescriptor r = it.next();
if (r.isWebServiceContext()) {
Iterator<InjectionTarget> iter = r.getInjectionTargets().iterator();
boolean matchingClassFound = false;
while (iter.hasNext()) {
InjectionTarget target = iter.next();
if (ejbDesc.getEjbClassName().equals(target.getClassName())) {
matchingClassFound = true;
break;
}
}
if (!matchingClassFound) {
continue;
}
try {
javax.naming.InitialContext ic = new javax.naming.InitialContext();
wsCtxt = (WebServiceContextImpl) ic.lookup("java:comp/env/" + r.getName());
} catch (Throwable t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogUtils.ERROR_EREI, t.getCause());
}
}
}
}
if (wsCtxt == null) {
wsCtxt = new WebServiceContextImpl();
}
} catch (Throwable t) {
LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
return null;
}
}
}
}
if (doPreInvoke) {
inv = container.startInvocation();
adapterInvInfo.setInv(inv);
}
// Now process handlers and init jaxws RI
synchronized (this) {
if (!handlersConfigured && doPreInvoke) {
try {
WsUtil wsu = new WsUtil();
String implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
Class clazz = container.getEndpointClassLoader().loadClass(implClassName);
// Get the proper binding using BindingID
String givenBinding = endpoint.getProtocolBinding();
// Get list of all wsdls and schema
SDDocumentSource primaryWsdl = null;
Collection docs = null;
if (endpoint.getWebService().hasWsdlFile()) {
WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
ApplicationRegistry appRegistry = wscImpl.getApplicationRegistry();
ApplicationInfo appInfo = appRegistry.get(endpoint.getBundleDescriptor().getApplication().getRegistrationName());
URI deployedDir = appInfo.getSource().getURI();
URL pkgedWsdl;
if (deployedDir != null) {
if (endpoint.getBundleDescriptor().getApplication().isVirtual()) {
pkgedWsdl = deployedDir.resolve(endpoint.getWebService().getWsdlFileUri()).toURL();
} else {
String moduleUri1 = endpoint.getBundleDescriptor().getModuleDescriptor().getArchiveUri();
// Fix for issue 7024099
// Only replace the last "." with "_" for moduleDescriptor's archive uri
String moduleUri = FileUtils.makeFriendlyFilenameExtension(moduleUri1);
pkgedWsdl = deployedDir.resolve(moduleUri + "/" + endpoint.getWebService().getWsdlFileUri()).toURL();
}
} else {
pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
}
if (pkgedWsdl != null) {
primaryWsdl = SDDocumentSource.create(pkgedWsdl);
docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
}
}
// Create a Container to pass ServletContext and also inserting the pipe
JAXWSContainer container = new JAXWSContainer(null, endpoint);
// Get catalog info
java.net.URL catalogURL = clazz.getResource('/' + endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + File.separator + "jax-ws-catalog.xml");
// Create Binding and set service side handlers on this binding
boolean mtomEnabled = wsu.getMtom(endpoint);
WSBinding binding = null;
ArrayList<WebServiceFeature> wsFeatures = new ArrayList<WebServiceFeature>();
// Only if MTOm is enabled create the Binding with the MTOMFeature
if (mtomEnabled) {
int mtomThreshold = endpoint.getMtomThreshold() != null ? Integer.parseInt(endpoint.getMtomThreshold()) : 0;
MTOMFeature mtom = new MTOMFeature(true, mtomThreshold);
wsFeatures.add(mtom);
}
Addressing addressing = endpoint.getAddressing();
if (endpoint.getAddressing() != null) {
AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
wsFeatures.add(addressingFeature);
}
if (wsFeatures.size() > 0) {
binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
} else {
binding = BindingID.parse(givenBinding).createBinding();
}
wsu.configureJAXWSServiceHandlers(endpoint, endpoint.getProtocolBinding(), binding);
// See if it is configured with JAX-WS extension InstanceResolver annotation like
// @com.sun.xml.ws.developer.servlet.HttpSessionScope or @com.sun.xml.ws.developer.Stateful
// #GLASSFISH-21081
InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(clazz);
// TODO - Implement 109 StatefulInstanceResolver ??
if (ir == null) {
// use our own InstanceResolver that does not call @PostConstuct method before
// @Resource injections have happened.
ir = new InstanceResolverImpl(clazz);
}
// Create the jaxws2.1 invoker and use this
Invoker invoker = ir.createInvoker();
WSEndpoint wsep = WSEndpoint.create(// The endpoint class
clazz, // we do not want JAXWS to process @HandlerChain
false, // the invoker
new EjbInvokerImpl(clazz, invoker, webServiceEndpointServant, wsCtxt), // the service QName
endpoint.getServiceName(), // the port
endpoint.getWsdlPort(), container, // Derive binding
binding, // primary WSDL
primaryWsdl, // Collection of imported WSDLs and schema
docs, catalogURL);
String uri = endpoint.getEndpointAddressUri();
String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
// All set; Create the adapter
if (adapterList == null) {
adapterList = new ServletAdapterList();
}
adapter = adapterList.createAdapter(endpoint.getName(), urlPattern, wsep);
handlersConfigured = true;
} catch (Throwable t) {
LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
adapter = null;
}
}
}
// set it using this method
synchronized (this) {
addWSContextInfo(wsCtxt);
if (inv != null && inv instanceof EJBInvocation) {
EJBInvocation ejbInv = (EJBInvocation) inv;
ejbInv.setWebServiceContext(wsCtxt);
}
}
adapterInvInfo.setAdapter(adapter);
return adapterInvInfo;
}
use of com.sun.xml.ws.api.server.SDDocumentSource in project Payara by payara.
the class WsUtil method addFileAndDecendents.
/*
* Add the File and wsdls and schemas imported by it to a list of metadata
* documents used to initialize an endpoint. Canonicalize the paths and check
* whether the documents have already been added to the list.
*/
private void addFileAndDecendents(URL fileUrl, ArrayList<SDDocumentSource> cumulative) throws Exception {
// make sure we have not processed this file before
boolean alreadyProcessed = false;
for (SDDocumentSource source : cumulative) {
if ((fileUrl.toString()).equals(source.getSystemId().toString())) {
alreadyProcessed = true;
break;
}
}
if (!alreadyProcessed) {
cumulative.add(0, SDDocumentSource.create(fileUrl));
getWsdlsAndSchemas(fileUrl, cumulative);
}
}
use of com.sun.xml.ws.api.server.SDDocumentSource in project Payara by payara.
the class WsUtil method getWsdlsAndSchemas.
/*public void downloadFile(URL httpUrl, File toFile) throws Exception {
InputStream is = null;
FileOutputStream os = null;
try {
if(!toFile.createNewFile()) {
throw new Exception("Unable to create new File " + toFile.getAbsolutePath());
}
is = httpUrl.openStream();
os = new FileOutputStream(toFile, true);
int readCount;
byte[] buffer = new byte[10240]; // Read 10KB at a time
while(true) {
readCount = is.read(buffer, 0, 10240);
if(readCount != -1) {
os.write(buffer, 0, readCount);
} else {
break;
}
}
} finally {
if(is != null) {
is.close();
}
if(os != null) {
os.flush();
os.close();
}
}
} */
public Collection getWsdlsAndSchemas(File pkgedWsdl) throws Exception {
ArrayList<SDDocumentSource> cumulative = new ArrayList<SDDocumentSource>();
getWsdlsAndSchemas(pkgedWsdl, cumulative);
// if there are circular imports of wsdls, the original wsdl might
// be in this Collection of imported metadata documents. If so, remove it.
URL id = pkgedWsdl.toURL();
SDDocumentSource toRemove = null;
for (SDDocumentSource source : cumulative) {
if ((id.toString()).equals(source.getSystemId().toString())) {
toRemove = source;
}
}
if (toRemove != null) {
cumulative.remove(toRemove);
}
return cumulative;
}
use of com.sun.xml.ws.api.server.SDDocumentSource in project Payara by payara.
the class WsUtil method getWsdlsAndSchemas.
/**
* This implementation is similar to #getWsdlsAndSchemas(File pkgedWsdl, except that this works on URL which makes
* it easy when the wsdl is loaded from the archive.
* @param pkgedWsdl URL
* @return
* @throws Exception
*/
public Collection getWsdlsAndSchemas(URL pkgedWsdl) throws Exception {
ArrayList<SDDocumentSource> cumulative = new ArrayList<SDDocumentSource>();
getWsdlsAndSchemas(pkgedWsdl, cumulative);
// if there are circular imports of wsdls, the original wsdl might
// be in this Collection of imported metadata documents. If so, remove it.
SDDocumentSource toRemove = null;
for (SDDocumentSource source : cumulative) {
if ((pkgedWsdl.toString()).equals(source.getSystemId().toString())) {
toRemove = source;
}
}
if (toRemove != null) {
cumulative.remove(toRemove);
}
return cumulative;
}
Aggregations