You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/06/20 20:59:42 UTC
svn commit: r415768 -
/webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java
Author: danj
Date: Tue Jun 20 11:59:42 2006
New Revision: 415768
URL: http://svn.apache.org/viewvc?rev=415768&view=rev
Log:
NOTE: Apparently, if you copy/paste a version of a file into
an SVN-based project in Tigris' Eclipse plugin, it causes the
file to be deleted, and you can then re-add it. Next time I
will make small changes directly (not in my sandbox).
Removed unused Messages field and subsequently the muse-util
dependency from muse-platform-axis2. The few NPEs being thrown
will be handled by JDK classes to which the method parameters
are handed off to in the first 1-2 statements.
Added:
webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java
Added: webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java?rev=415768&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java (added)
+++ webservices/muse/trunk/modules/muse-platform-axis2/src/org/apache/muse/core/platform/axis2/AxisEnvironment.java Tue Jun 20 11:59:42 2006
@@ -0,0 +1,250 @@
+/*=============================================================================*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.core.platform.axis2;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+import org.apache.muse.core.AbstractEnvironment;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.WsaConstants;
+
+/**
+ *
+ * AxisEnvironment is an extension of {@linkplain AbstractEnvironment AbstractEnvironment}
+ * for the Apache Axis 1.x SOAP engine. It provides all of the lower-level
+ * functionality that is abstracted through the Environment interface using
+ * the local file system and Axis2 context APIs.
+ *
+ * @author Dan Jemiolo (danjemiolo)
+ *
+ */
+
+public class AxisEnvironment extends AbstractEnvironment
+{
+ //
+ // The service installation directory (NOT the WAR file directory)
+ //
+ private File _realDirectory = null;
+
+ /**
+ *
+ * This constructor determines the value of the "real directory" - where
+ * the application is installed on the file system so that it can read
+ * local files when it needs to.
+ *
+ * @param opContext
+ *
+ */
+ public AxisEnvironment(OperationContext opContext)
+ {
+ addContext(opContext);
+ MessageContext message = getInputMessageContext();
+
+ //
+ // where are we? this is the path of the service installation,
+ // not of the Axis2 WAR
+ //
+ String realDirPath = message.getAxisService().getFileName().getFile();
+ _realDirectory = new File(realDirPath);
+
+ String addressString = message.getTo().getAddress();
+ URI address = URI.create(addressString);
+ setDefaultURI(getDeploymentURI(address));
+ }
+
+ public static OMElement convertToAxiom(Element xml)
+ {
+ String xmlString = XmlUtils.toString(xml, false);
+ byte[] xmlBytes = xmlString.getBytes();
+ StAXOMBuilder builder = null;
+
+ try
+ {
+ builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ }
+
+ catch (XMLStreamException error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+
+ return builder.getDocumentElement();
+ }
+
+ public static Element convertToDOM(OMElement axiom)
+ {
+ try
+ {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ axiom.serialize(output);
+
+ byte[] bytes = output.toByteArray();
+ ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+
+ Document doc = XmlUtils.createDocument(input);
+ return XmlUtils.getFirstElement(doc);
+ }
+
+ catch (Throwable error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+ }
+
+ public URL getDataResource(String path)
+ {
+ File file = new File(_realDirectory, path);
+
+ try
+ {
+ return file.toURL();
+ }
+
+ catch (MalformedURLException error)
+ {
+ throw new RuntimeException(error);
+ }
+ }
+
+ public InputStream getDataResourceStream(String path)
+ {
+ File file = new File(getRealDirectory(), path);
+
+ try
+ {
+ return new FileInputStream(file);
+ }
+
+ catch (FileNotFoundException error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+ }
+
+ public EndpointReference getDeploymentEPR()
+ {
+ return getDefaultEPR();
+ }
+
+ public final MessageContext getInputMessageContext()
+ {
+ try
+ {
+ OperationContext opContext = (OperationContext)getContext();
+ return opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ }
+
+ catch (AxisFault error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+ }
+
+ public final MessageContext getOutputMessageContext()
+ {
+ try
+ {
+ OperationContext opContext = (OperationContext)getContext();
+ return opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+ }
+
+ catch (AxisFault error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+ }
+
+ public File getRealDirectory()
+ {
+ return _realDirectory;
+ }
+
+ public EndpointReference getTargetEPR()
+ {
+ //
+ // the Axis2 MessageContext has the EPR we want, but it's an
+ // Axis2 EPR - we want to use our generic API. hopefully this
+ // code can be removed once we support JSR 261 or have Addressing
+ // in Apache WS Commons
+ //
+ MessageContext message = getInputMessageContext();
+ org.apache.axis2.addressing.EndpointReference axisEPR = message.getTo();
+
+ try
+ {
+ OMElement axisXML = axisEPR.toOM(WsaConstants.NAMESPACE_URI, "EndpointReference", WsaConstants.PREFIX);
+ Element eprXML = convertToDOM(axisXML);
+
+ //
+ // FIXME: for some reason, Axis2 is adding the reference parameters
+ // to the Metadata section of the EPR, even though the
+ // IsReferenceParameter attribute is qualified with the WS-A
+ // namespace. if this cannot be fixed immediately, a hack to
+ // swap metadata to parameters should be added here (and it
+ // should look like the code below).
+ //
+ /*
+ Element metadata = XmlUtils.getElement(eprXML, WsaConstants.METADATA_QNAME);
+
+ if (metadata != null)
+ {
+ eprXML.removeChild(metadata);
+
+ Document doc = eprXML.getOwnerDocument();
+ Element params = XmlUtils.createElement(doc, WsaConstants.PARAMETERS_QNAME);
+ eprXML.appendChild(params);
+
+ Element[] children = XmlUtils.getAllElements(metadata);
+
+ for (int n = 0; n < children.length; ++n)
+ {
+ metadata.removeChild(children[n]);
+ params.appendChild(children[n]);
+ }
+ }
+ */
+
+ return new EndpointReference(eprXML);
+ }
+
+ catch (Throwable error)
+ {
+ throw new RuntimeException(error.getMessage(), error);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org