use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class ContextUtils method addProperties.
/**
* Adds the appropriate properties to the MessageContext that the user will see
*
* @param soapMessageContext
* @param jaxwsMessageContext
*/
public static void addProperties(SOAPMessageContext soapMessageContext, MessageContext jaxwsMessageContext) {
// Copy Axis2 MessageContext properties. It's possible that some set of Axis2 handlers
// have run and placed some properties in the context that need to be visible.
soapMessageContext.putAll(jaxwsMessageContext.getProperties());
EndpointDescription description = jaxwsMessageContext.getEndpointDescription();
if (description != null) {
// Set the WSDL properties
ServiceDescription sd = description.getServiceDescription();
if (sd != null) {
String wsdlLocation = ((ServiceDescriptionWSDL) sd).getWSDLLocation();
if (wsdlLocation != null && !"".equals(wsdlLocation)) {
URI wsdlLocationURI = JavaUtils.createURI(wsdlLocation);
if (wsdlLocationURI == null) {
log.warn(Messages.getMessage("addPropertiesErr", wsdlLocation.toString(), description.getServiceQName().toString()));
}
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION, wsdlLocationURI, true);
}
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.WSDL_SERVICE, description.getServiceQName(), true);
}
}
// Lazily provide a list of available reference parameters.
org.apache.axis2.context.MessageContext msgContext = jaxwsMessageContext.getAxisMessageContext();
SOAPHeader header = null;
if (msgContext != null && msgContext.getEnvelope() != null) {
header = msgContext.getEnvelope().getHeader();
}
List<Element> list = new ReferenceParameterList(header);
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.REFERENCE_PARAMETERS, list);
if (log.isDebugEnabled()) {
log.debug("Added reference parameter list.");
}
// If we are running within a servlet container, then JAX-WS requires that the
// servlet related properties be set on the MessageContext
ServletContext servletContext = (ServletContext) jaxwsMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
if (servletContext != null) {
log.debug("Servlet Context Set");
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT, servletContext);
} else {
log.debug("Servlet Context not found");
}
HttpServletRequest req = (HttpServletRequest) jaxwsMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
if (req == null) {
if (log.isDebugEnabled()) {
log.debug("HTTPServletRequest not found");
}
} else {
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.SERVLET_REQUEST, req);
if (log.isDebugEnabled()) {
log.debug("SERVLET_REQUEST Set");
}
String pathInfo = null;
try {
pathInfo = req.getPathInfo();
} catch (Throwable t) {
log.debug("exception in getPathInfo", t);
}
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.PATH_INFO, pathInfo);
if (log.isDebugEnabled()) {
if (pathInfo != null) {
log.debug("HTTP_REQUEST_PATHINFO Set");
} else {
log.debug("HTTP_REQUEST_PATHINFO not found");
}
}
String queryString = req.getQueryString();
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.QUERY_STRING, queryString);
if (log.isDebugEnabled()) {
if (queryString != null) {
log.debug("HTTP_REQUEST_QUERYSTRING Set");
} else {
log.debug("HTTP_REQUEST_QUERYSTRING not found");
}
}
String method = req.getMethod();
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.HTTP_REQUEST_METHOD, method);
if (log.isDebugEnabled()) {
if (method != null) {
log.debug("HTTP_REQUEST_METHOD Set");
} else {
log.debug("HTTP_REQUEST_METHOD not found");
}
}
}
HttpServletResponse res = (HttpServletResponse) jaxwsMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);
if (res == null) {
if (log.isDebugEnabled()) {
log.debug("Servlet Response not found");
}
} else {
setProperty(soapMessageContext, javax.xml.ws.handler.MessageContext.SERVLET_RESPONSE, res);
if (log.isDebugEnabled()) {
log.debug("SERVLET_RESPONSE Set");
}
}
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class EndpointReferenceUtils method addLocation.
/**
* @param axis2EPR
* @param targetNamespace
* @param wsdlDocumentLocation
* @param addressingNamespace
* @throws Exception
*/
public static void addLocation(EndpointReference axis2EPR, String targetNamespace, String wsdlDocumentLocation, String addressingNamespace) throws Exception {
if (targetNamespace != null && wsdlDocumentLocation != null) {
WSDLLocation wsdlLocation = new WSDLLocation(targetNamespace, wsdlDocumentLocation);
EndpointReferenceHelper.setWSDLLocationMetadata(omFactory, axis2EPR, addressingNamespace, wsdlLocation);
}
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class ServiceDeployer method populateService.
/*
* TODO - This method is used by deployFromUrl() method and this should be
* refactored to reduce code complexity.
*/
protected ArrayList<AxisService> populateService(AxisServiceGroup serviceGroup, URL servicesURL, String serviceName) throws DeploymentException {
try {
serviceGroup.setServiceGroupName(serviceName);
ClassLoader serviceClassLoader = Utils.createClassLoader(servicesURL, null, axisConfig.getServiceClassLoader(), (File) axisConfig.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR), axisConfig.isChildFirstClassLoading());
String metainf = "meta-inf";
serviceGroup.setServiceGroupClassLoader(serviceClassLoader);
// processing wsdl.list
InputStream wsdlfilesStream = serviceClassLoader.getResourceAsStream("meta-inf/wsdl.list");
if (wsdlfilesStream == null) {
wsdlfilesStream = serviceClassLoader.getResourceAsStream("META-INF/wsdl.list");
if (wsdlfilesStream != null) {
metainf = "META-INF";
}
}
HashMap<String, AxisService> servicesMap = new HashMap<String, AxisService>();
if (wsdlfilesStream != null) {
ArchiveReader reader = new ArchiveReader();
BufferedReader input = new BufferedReader(new InputStreamReader(wsdlfilesStream));
String line;
while ((line = input.readLine()) != null) {
line = line.trim();
if (line.length() > 0 && line.charAt(0) != '#') {
line = metainf + "/" + line;
try {
List<AxisService> services = reader.getAxisServiceFromWsdl(serviceClassLoader.getResourceAsStream(line), serviceClassLoader, line);
if (services != null) {
for (Object service : services) {
AxisService axisService = (AxisService) service;
servicesMap.put(axisService.getName(), axisService);
}
}
} catch (Exception e) {
throw new DeploymentException(e);
}
}
}
}
InputStream servicexmlStream = serviceClassLoader.getResourceAsStream("META-INF/services.xml");
if (servicexmlStream == null) {
servicexmlStream = serviceClassLoader.getResourceAsStream("meta-inf/services.xml");
} else {
metainf = "META-INF";
}
if (servicexmlStream == null) {
throw new DeploymentException(Messages.getMessage(DeploymentErrorMsgs.SERVICE_XML_NOT_FOUND, servicesURL.toString()));
}
DescriptionBuilder builder = new DescriptionBuilder(servicexmlStream, configCtx);
OMElement rootElement = builder.buildOM();
String elementName = rootElement.getLocalName();
if (DeploymentConstants.TAG_SERVICE.equals(elementName)) {
AxisService axisService = null;
String wsdlLocation = "META-INF/service.wsdl";
InputStream wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation);
URL wsdlURL = serviceClassLoader.getResource(metainf + "/service.wsdl");
if (wsdlStream == null) {
wsdlLocation = "META-INF/" + serviceName + ".wsdl";
wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation);
wsdlURL = serviceClassLoader.getResource(wsdlLocation);
}
if (wsdlStream != null) {
WSDL11ToAxisServiceBuilder wsdl2AxisServiceBuilder = new WSDL11ToAxisServiceBuilder(wsdlStream, null, null);
File file = Utils.toFile(servicesURL);
if (file != null && file.exists()) {
wsdl2AxisServiceBuilder.setCustomWSDLResolver(new AARBasedWSDLLocator(wsdlLocation, file, wsdlStream));
wsdl2AxisServiceBuilder.setCustomResolver(new AARFileBasedURIResolver(file));
}
if (wsdlURL != null) {
wsdl2AxisServiceBuilder.setDocumentBaseUri(wsdlURL.toString());
}
axisService = wsdl2AxisServiceBuilder.populateService();
axisService.setWsdlFound(true);
axisService.setCustomWsdl(true);
axisService.setName(serviceName);
}
if (axisService == null) {
axisService = new AxisService(serviceName);
}
axisService.setParent(serviceGroup);
axisService.setClassLoader(serviceClassLoader);
ServiceBuilder serviceBuilder = new ServiceBuilder(configCtx, axisService);
AxisService service = serviceBuilder.populateService(rootElement);
ArrayList<AxisService> serviceList = new ArrayList<AxisService>();
serviceList.add(service);
return serviceList;
} else if (DeploymentConstants.TAG_SERVICE_GROUP.equals(elementName)) {
ServiceGroupBuilder groupBuilder = new ServiceGroupBuilder(rootElement, servicesMap, configCtx);
ArrayList<AxisService> servicList = groupBuilder.populateServiceGroup(serviceGroup);
Iterator<AxisService> serviceIterator = servicList.iterator();
while (serviceIterator.hasNext()) {
AxisService axisService = (AxisService) serviceIterator.next();
String wsdlLocation = "META-INF/service.wsdl";
InputStream wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation);
URL wsdlURL = serviceClassLoader.getResource(wsdlLocation);
if (wsdlStream == null) {
wsdlLocation = "META-INF/" + serviceName + ".wsdl";
wsdlStream = serviceClassLoader.getResourceAsStream(wsdlLocation);
wsdlURL = serviceClassLoader.getResource(wsdlLocation);
}
if (wsdlStream != null) {
WSDL11ToAxisServiceBuilder wsdl2AxisServiceBuilder = new WSDL11ToAxisServiceBuilder(wsdlStream, axisService);
File file = Utils.toFile(servicesURL);
if (file != null && file.exists()) {
wsdl2AxisServiceBuilder.setCustomWSDLResolver(new AARBasedWSDLLocator(wsdlLocation, file, wsdlStream));
wsdl2AxisServiceBuilder.setCustomResolver(new AARFileBasedURIResolver(file));
}
if (wsdlURL != null) {
wsdl2AxisServiceBuilder.setDocumentBaseUri(wsdlURL.toString());
}
axisService = wsdl2AxisServiceBuilder.populateService();
axisService.setWsdlFound(true);
axisService.setCustomWsdl(true);
// Set the default message receiver for the operations
// that were
// not listed in the services.xml
Iterator<AxisOperation> operations = axisService.getOperations();
while (operations.hasNext()) {
AxisOperation operation = (AxisOperation) operations.next();
if (operation.getMessageReceiver() == null) {
operation.setMessageReceiver(loadDefaultMessageReceiver(operation.getMessageExchangePattern(), axisService));
}
}
}
}
return servicList;
}
} catch (IOException e) {
throw new DeploymentException(e);
} catch (XMLStreamException e) {
throw new DeploymentException(e);
}
return null;
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class WSDL11ToAxisServiceBuilderTest method testUsingAddressing.
// Check the addressing requirement parameter is set to
// ADDRESSING_OPTIONAL when <wsaw:UsingAddressing /> is used in the WSDL
public void testUsingAddressing() {
wsdlLocation = System.getProperty("basedir", ".") + "/" + "test-resources/wsdl/UsingAddressing.wsdl";
File testResourceFile = new File(wsdlLocation);
try {
WSDL11ToAllAxisServicesBuilder builder = new WSDL11ToAllAxisServicesBuilder(new FileInputStream(testResourceFile));
AxisService axisService = builder.populateService();
String addressingRequired = AddressingHelper.getAddressingRequirementParemeterValue(axisService);
assertEquals("Unexpected addressingRequirementParameter value: " + addressingRequired, AddressingConstants.ADDRESSING_OPTIONAL, addressingRequired);
} catch (Exception e) {
System.out.println("Error in WSDL : " + testResourceFile.getName());
System.out.println("Exception: " + e.toString());
fail("Caught exception " + e.toString());
}
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class WSDL11ToAxisServiceBuilderTest method testUsingAddressingOptional.
// Check the addressing requirement parameter is set to
// ADDRESSING_OPTIONAL when <wsaw:UsingAddressing wsdl:required="false" />
// is used in the WSDL
public void testUsingAddressingOptional() {
wsdlLocation = System.getProperty("basedir", ".") + "/" + "test-resources/wsdl/UsingAddressingOptional.wsdl";
File testResourceFile = new File(wsdlLocation);
try {
WSDL11ToAllAxisServicesBuilder builder = new WSDL11ToAllAxisServicesBuilder(new FileInputStream(testResourceFile));
AxisService axisService = builder.populateService();
String addressingRequired = AddressingHelper.getAddressingRequirementParemeterValue(axisService);
assertEquals("Unexpected addressingRequirementParameter value: " + addressingRequired, AddressingConstants.ADDRESSING_OPTIONAL, addressingRequired);
} catch (Exception e) {
System.out.println("Error in WSDL : " + testResourceFile.getName());
System.out.println("Exception: " + e.toString());
fail("Caught exception " + e.toString());
}
}
Aggregations