Author: tli
Date: Fri Sep 1 01:15:15 2006
New Revision: 439229
URL: http://svn.apache.org/viewvc?rev=439229&view=rev
Log:
xml interceptors
Added:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java
(with props)
Modified:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
Added:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java?rev=439229&view=auto
==============================================================================
---
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java
(added)
+++
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java
Fri Sep 1 01:15:15 2006
@@ -0,0 +1,30 @@
+/**
+ * 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.cxf.binding.xml.interceptor;
+
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+
+public abstract class AbstractXMLBindingInterceptor extends
AbstractPhaseInterceptor {
+
+ protected boolean isRequestor(org.apache.cxf.message.Message message) {
+ return Boolean.TRUE.equals(message.containsKey(
+ org.apache.cxf.message.Message.REQUESTOR_ROLE));
+ }
+}
Propchange:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/AbstractXMLBindingInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java?rev=439229&r1=439228&r2=439229&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
Fri Sep 1 01:15:15 2006
@@ -16,19 +16,77 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.cxf.binding.xml.interceptor;
+import java.util.ResourceBundle;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.bindings.xformat.XMLBindingMessageFormat;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.BareInInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.WrappedInInterceptor;
import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
-public class XMLMessageInInterceptor extends AbstractPhaseInterceptor {
+public class XMLMessageInInterceptor
+ extends AbstractXMLBindingInterceptor {
+
+ private static final ResourceBundle BUNDLE =
BundleUtils.getBundle(WrappedInInterceptor.class);
public void handleMessage(Message message) throws Fault {
- new WrappedInInterceptor().handleMessage(message);
- new BareInInterceptor().handleMessage(message);
+ XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
+ DepthXMLStreamReader dxsr = new DepthXMLStreamReader(xsr);
+ Endpoint ep = message.getExchange().get(Endpoint.class);
+ BindingInfo service = ep.getEndpointInfo().getBinding();
+ boolean result = false;
+ for (BindingOperationInfo boi : service.getOperations()) {
+ if (!boi.isUnwrappedCapable()) {
+ // process bare mode
+ MessageInfo mi;
+ if (isRequestor(message)) {
+ mi = boi.getOperationInfo().getInput();
+ } else {
+ mi = boi.getOperationInfo().getOutput();
+ }
+ if (mi.getMessageParts().size() != 1) {
+ // Part more than 1, needs a root, which should match the
+ // root defined in wsdl binding
+ // Retrive the root value from input message xml infoset
+ if (!StaxUtils.toNextElement(dxsr)) {
+ throw new Fault(
+ new
org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT", BUNDLE));
+ }
+ String rootMsg = dxsr.getLocalName();
+ String rootInModel = ((XMLBindingMessageFormat) mi
+
.getExtensor(XMLBindingMessageFormat.class)).getRootNode();
+ if (rootInModel != null && rootInModel.equals(rootMsg)) {
+ message.getExchange().put(BindingOperationInfo.class,
boi);
+ new BareInInterceptor().handleMessage(message);
+ result = true;
+ break;
+ }
+ } else {
+ // Only one part, no root, using the BareInInterceptor
inner
+ // logic to find operation
+ new BareInInterceptor().handleMessage(message);
+ result = true;
+ break;
+ }
+ } else {
+ // process wrap mode
+ new WrappedInInterceptor().handleMessage(message);
+ }
+ }
+ if (!result) {
+ // fault processing
+ }
}
-
}
Modified:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java?rev=439229&r1=439228&r2=439229&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageOutInterceptor.java
Fri Sep 1 01:15:15 2006
@@ -18,18 +18,60 @@
*/
package org.apache.cxf.binding.xml.interceptor;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.bindings.xformat.XMLBindingMessageFormat;
+import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.interceptor.BareOutInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.WrappedOutInterceptor;
import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessageInfo;
-public class XMLMessageOutInterceptor extends AbstractPhaseInterceptor {
+public class XMLMessageOutInterceptor extends AbstractXMLBindingInterceptor {
+
+ private static final ResourceBundle BUNDLE =
BundleUtils.getBundle(WrappedOutInterceptor.class);
public void handleMessage(Message message) throws Fault {
- new WrappedOutInterceptor().handleMessage(message);
- new BareOutInterceptor().handleFault(message);
+ MessageInfo mi;
+ BindingOperationInfo boi =
message.getExchange().get(BindingOperationInfo.class);
+ if (isRequestor(message)) {
+ mi = boi.getOperationInfo().getInput();
+ } else {
+ mi = boi.getOperationInfo().getOutput();
+ }
+ String rootInModel = ((XMLBindingMessageFormat)
mi.getExtensor(XMLBindingMessageFormat.class))
+ .getRootNode();
+
+ if (boi.isUnwrapped()) {
+ if (mi.getMessageParts().size() != 1) {
+ if (rootInModel == null) {
+ throw new RuntimeException("Bare style must define the
rootNode in this case!");
+ }
+ XMLStreamWriter xmlWriter =
message.getContent(XMLStreamWriter.class);
+
+ MessageInfo messageInfo = message.get(MessageInfo.class);
+ QName name = messageInfo.getName();
+
+ try {
+ xmlWriter.writeStartElement(name.getLocalPart(),
name.getNamespaceURI());
+ new BareOutInterceptor().handleMessage(message);
+ xmlWriter.writeEndElement();
+ } catch (XMLStreamException e) {
+ throw new Fault(new
org.apache.cxf.common.i18n.Message("STAX_READ_EXC", BUNDLE, e));
+ }
+
+ } else {
+ new BareOutInterceptor().handleMessage(message);
+ }
+
+ }
}
}