You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by th...@apache.org on 2008/11/28 06:10:29 UTC
svn commit: r721338 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: ./
builder/ builder/unknowncontent/ engine/
Author: thilina
Date: Thu Nov 27 21:10:28 2008
New Revision: 721338
URL: http://svn.apache.org/viewvc?rev=721338&view=rev
Log:
fixing axis2-4153. Adding a unknown content builder, which will wrap any content it receives as a binary Data handler. This can be switched on/off using 'useDefaultFallbackBuilder' parameter in Axis2 configuration. By default it's not used.
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/InputStreamDataSource.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentBuilder.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentOMDataSource.java
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?rev=721338&r1=721337&r2=721338&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Thu Nov 27 21:10:28 2008
@@ -390,6 +390,13 @@
public static final String MESSAGE_TYPE = "messageType";
public static final String MESSAGE_FORMATTER = "messageFormatter";
+
+ /**
+ * This is used to enable/disable Axis2 default fall back builder. When enabled Axis2
+ * will build any message that has a content type which is not supported by the configured
+ * Axis2 builder will be built using this builder.
+ */
+ public static final String USE_DEFAULT_FALLBACK_BUILDER = "useDefaultFallbackBuilder";
public static final String SOAP_RESPONSE_MEP = "soapResponseMEP";
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?rev=721338&r1=721337&r2=721338&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java Thu Nov 27 21:10:28 2008
@@ -65,6 +65,8 @@
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaType;
+import com.sun.corba.se.impl.copyobject.FallbackObjectCopierImpl;
+
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
import javax.xml.parsers.FactoryConfigurationError;
@@ -712,17 +714,20 @@
*/
public static Builder getBuilderFromSelector(String type, MessageContext msgContext)
throws AxisFault {
-
+ boolean useFallbackBuilder = false;
AxisConfiguration configuration =
msgContext.getConfigurationContext().getAxisConfiguration();
- Builder builder = configuration.getMessageBuilder(type);
+ Parameter useFallbackParameter = configuration.getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER);
+ if (useFallbackParameter !=null){
+ useFallbackBuilder = JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(),useFallbackBuilder);
+ }
+ Builder builder = configuration.getMessageBuilder(type,useFallbackBuilder);
if (builder != null) {
// Check whether the request has a Accept header if so use that as the response
// message type.
// If thats not present,
// Setting the received content-type as the messageType to make
- // sure that we respond using the received message serialisation
- // format.
+ // sure that we respond using the received message serialization format.
Object contentNegotiation = configuration
.getParameterValue(Constants.Configuration.ENABLE_HTTP_CONTENT_NEGOTIATION);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java?rev=721338&r1=721337&r2=721338&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MIMEBuilder.java Thu Nov 27 21:10:28 2008
@@ -63,8 +63,7 @@
ct = new ContentType(contentType);
} catch (ParseException e) {
throw new OMException(
- "Invalid Content Type Field in the Mime Message"
- , e);
+ "Invalid Content Type Field in the Mime Message", e);
}
String type = ct.getParameter("type");
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/InputStreamDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/InputStreamDataSource.java?rev=721338&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/InputStreamDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/InputStreamDataSource.java Thu Nov 27 21:10:28 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axis2.builder.unknowncontent;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+public class InputStreamDataSource implements DataSource {
+
+ private InputStream inStream;
+
+ private String type;
+
+ public InputStreamDataSource(InputStream inputStream) {
+ super();
+ this.inStream = inputStream;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getContentType() {
+ if (type == null)
+ return "application/octet-stream";
+ else
+ return type;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return inStream;
+ }
+
+ public String getName() {
+ return "InputStreamDataSource";
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ throw new IOException("Not Supported");
+ }
+}
+
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentBuilder.java?rev=721338&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentBuilder.java Thu Nov 27 21:10:28 2008
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axis2.builder.unknowncontent;
+
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.builder.Builder;
+import org.apache.axis2.context.MessageContext;
+
+public class UnknownContentBuilder implements Builder {
+
+ public OMElement processDocument(InputStream inputStream,
+ String contentType, MessageContext messageContext) throws AxisFault {
+
+ // using this to figure out whether the received is a MIME message
+ if (messageContext.isDoingSwA()) {
+ String rootPartContentID = messageContext.attachments
+ .getSOAPPartContentID();
+ DataHandler rootPartDataHandler = messageContext.attachments
+ .getDataHandler(rootPartContentID);
+ UnknownContentOMDataSource unknownContentDataSource = new UnknownContentOMDataSource(
+ rootPartDataHandler);
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ messageContext.setDoingSwA(false);
+ messageContext.setDoingMTOM(false);
+ return new OMSourcedElementImpl(
+ UnknownContentOMDataSource.unknownContentQName, factory,
+ unknownContentDataSource);
+ }
+ InputStreamDataSource inStreamDataSource = new InputStreamDataSource(
+ inputStream);
+ inStreamDataSource.setType(contentType);
+ DataHandler dataHandler = new DataHandler(inStreamDataSource);
+ UnknownContentOMDataSource unknownContentDataSource = new UnknownContentOMDataSource(
+ dataHandler);
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ return new OMSourcedElementImpl(
+ UnknownContentOMDataSource.unknownContentQName, factory,
+ unknownContentDataSource);
+ }
+}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentOMDataSource.java?rev=721338&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentOMDataSource.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/unknowncontent/UnknownContentOMDataSource.java Thu Nov 27 21:10:28 2008
@@ -0,0 +1,82 @@
+package org.apache.axis2.builder.unknowncontent;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.OutputStream;
+import java.io.Writer;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axis2.transport.MessageFormatter;
+
+public class UnknownContentOMDataSource implements OMDataSource {
+
+ public static QName unknownContentQName = new QName(
+ "http://ws.apache.org/axis2", "UnknownContent");
+
+ DataHandler genericContent;
+ OMElement wrapperElement;
+
+ public UnknownContentOMDataSource(DataHandler rootDataHandler) {
+ genericContent = rootDataHandler;
+ wrapperElement = createElement();
+ }
+
+ public XMLStreamReader getReader() throws XMLStreamException {
+ return wrapperElement.getXMLStreamReader();
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ wrapperElement.serialize(output,format);
+ }
+
+ public void serialize(Writer writer, OMOutputFormat format)
+ throws XMLStreamException {
+ wrapperElement.serialize(writer,format);
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ wrapperElement.serialize(xmlWriter);
+ }
+
+ public DataHandler getContent() {
+ return genericContent;
+ }
+
+ private OMElement createElement()
+ {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMText textNode = factory.createOMText(genericContent, true);
+ OMElement wrapperElement = factory.createOMElement(unknownContentQName);
+ wrapperElement.addChild(textNode);
+ return wrapperElement;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java?rev=721338&r1=721337&r2=721338&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java Thu Nov 27 21:10:28 2008
@@ -21,6 +21,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.builder.Builder;
+import org.apache.axis2.builder.unknowncontent.UnknownContentBuilder;
import org.apache.axis2.clustering.ClusterManager;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.dataretrieval.AxisDataLocator;
@@ -664,31 +665,43 @@
* the given content type.
*/
public Builder getMessageBuilder(String contentType) {
- if(messageBuilders.isEmpty()){
- return null;
- }
- Builder builder = (Builder) messageBuilders.get(contentType);
- if (builder == null) {
- builder = (Builder) messageBuilders.get(contentType.toLowerCase());
- }
- if (builder == null) {
- Iterator iterator = messageBuilders.entrySet().iterator();
- while (iterator.hasNext() && builder == null) {
- Map.Entry entry = (Map.Entry) iterator.next();
- String key = (String) entry.getKey();
- if (contentType.matches(key)) {
- builder = (Builder) entry.getValue();
- }
- }
- }
- return builder;
- }
+ Builder builder = null;
+ if (messageBuilders.isEmpty()) {
+ return null;
+ }
+ if (contentType != null) {
+ builder = (Builder) messageBuilders.get(contentType);
+ if (builder == null) {
+ builder = (Builder) messageBuilders.get(contentType
+ .toLowerCase());
+ }
+ if (builder == null) {
+ Iterator iterator = messageBuilders.entrySet().iterator();
+ while (iterator.hasNext() && builder == null) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ String key = (String) entry.getKey();
+ if (contentType.matches(key)) {
+ builder = (Builder) entry.getValue();
+ }
+ }
+ }
+ }
+ return builder;
+ }
+
+ public Builder getMessageBuilder(String contentType, boolean defaultBuilder) {
+ Builder builder = getMessageBuilder(contentType);
+ if (builder ==null & defaultBuilder){
+ builder = new UnknownContentBuilder();
+ }
+ return builder;
+ }
/**
- * @param contentType
- * @return the configured message formatter implementation class name
- * against the given content type.
- */
+ * @param contentType
+ * @return the configured message formatter implementation class name
+ * against the given content type.
+ */
public MessageFormatter getMessageFormatter(String contentType) {
return (MessageFormatter) messageFormatters.get(contentType);
}