You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2007/12/11 03:54:23 UTC
svn commit: r603133 - in
/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src:
main/java/org/apache/servicemix/cxfse/
main/java/org/apache/servicemix/cxfse/interceptors/
test/java/org/apache/servicemix/cxfse/
Author: ffang
Date: Mon Dec 10 18:54:22 2007
New Revision: 603133
URL: http://svn.apache.org/viewvc?rev=603133&view=rev
Log:
[SM-1163] CXF SE missing type attribute in jbi outbound message
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties (with props)
servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java (with props)
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeSpringTest.java
Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java?rev=603133&r1=603132&r2=603133&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java Mon Dec 10 18:54:22 2007
@@ -18,6 +18,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -34,6 +35,7 @@
import javax.xml.ws.WebServiceRef;
import org.apache.cxf.Bus;
+import org.apache.cxf.binding.jbi.interceptor.JBIWrapperOutInterceptor;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.interceptor.InterceptorProvider;
import org.apache.cxf.jaxws.EndpointImpl;
@@ -48,6 +50,7 @@
import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
import org.apache.servicemix.common.endpoints.ProviderEndpoint;
import org.apache.servicemix.cxfse.interceptors.AttachmentInInterceptor;
+import org.apache.servicemix.cxfse.interceptors.WrapperOutInterceptor;
import org.apache.servicemix.cxfse.support.ReflectionUtils;
import org.apache.servicemix.id.IdGenerator;
import org.springframework.util.ReflectionUtils.FieldCallback;
@@ -156,6 +159,7 @@
endpoint.setInFaultInterceptors(getInFaultInterceptors());
endpoint.setOutInterceptors(getOutInterceptors());
endpoint.setOutFaultInterceptors(getOutFaultInterceptors());
+ endpoint.getOutInterceptors().add(new WrapperOutInterceptor());
if (isMtomEnabled()) {
endpoint.getInInterceptors().add(new AttachmentInInterceptor());
}
@@ -199,6 +203,7 @@
super.start();
address = "jbi://" + ID_GENERATOR.generateSanitizedId();
endpoint.publish(address);
+ removeJBIWrapperInterceptor(endpoint.getServer().getEndpoint().getBinding().getOutInterceptors());
setService(endpoint.getServer().getEndpoint().getService().getName());
setEndpoint(endpoint.getServer().getEndpoint().getEndpointInfo()
.getName().getLocalPart());
@@ -226,6 +231,18 @@
});
ReflectionUtils.callLifecycleMethod(getPojo(), PostConstruct.class);
injectPojo();
+ }
+
+ private void removeJBIWrapperInterceptor(List<Interceptor> outInterceptors) {
+
+ Iterator<Interceptor> iter = outInterceptors.iterator();
+ while (iter.hasNext()) {
+ Interceptor interceptor = iter.next();
+ if (interceptor instanceof JBIWrapperOutInterceptor) {
+ outInterceptors.remove(interceptor);
+ break;
+ }
+ }
}
/*
Added: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties?rev=603133&view=auto
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties (added)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties Mon Dec 10 18:54:22 2007
@@ -0,0 +1,61 @@
+#
+# 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.
+#
+NOT.IMPLEMENTED=not yet implemented
+INVOKE.SERVICE=invoking service\t
+CREATE.MESSAGE.EXCHANGE=create message exchange svc:\t
+EXCHANGE.ENDPOINT=exchange endpoint:\t
+NO.MESSAGE=no message yet
+UNABLE.RETRIEVE.MESSAGE=unable to retrieve message
+CONTEXT.MUST.BE=context must be of type JBIOutputStreamMessageContext
+RECEIVED.MESSAGE=received message:\t
+ACTIVE.JBI.SERVER.TRANSPORT=activating JBI server transport
+BUILDING.DOCUMENT=building document from bytes
+CREATE.NORMALIZED.MESSAGE=creating NormalizedMessage
+POST.DISPATCH=postDispatch sending out message to NWR
+ERROR.SEND.MESSAGE=error sending Out message
+DISPATCH.MESSAGE.ON.CALLBACK=dispatching message on callback:\t
+ERROR.PREPARE.MESSAGE=error preparing message
+RECEIVE.THREAD.START=JBIServerTransport message receiving thread started
+DISPATCH.TO.SU=dispatching to CXF service unit
+NO.SU.FOUND=no CXFServiceUnit found
+ERROR.DISPATCH.THREAD=error running dispatch thread
+JBI.SERVER.TRANSPORT.MESSAGE.PROCESS.THREAD.EXIT=JBIServerTransport message processing thread exiting
+CONFIG.DELIVERY.CHANNEL=configuring DeliveryChannel:\t
+CONFIG.SU.MANAGER=configuring ServiceUnitManager:\t
+JBI.TRANSPORT.FACTORY.NOT.INITIALIZED=JBITransportFactory is not properly initialized
+SU.MANAGER=CXFServiceUnitManager:\t
+DELIVERY.CHANNEL=DeliveryChannel:\t
+JBI.TRANSPORT.FACTORY.NOT.FULLY.INITIALIZED=JBITransport factory not fully initialized
+CREATE.SERVER.TRANSPORT=creating JBI server transport
+CREATE.CLIENT.TRANSPORT=creating JBI client transport
+UNKNOWN_OPERATION=unknown operation {0}
+NO_OPERATION_ELEMENT=no operation element
+NO_JBI_MESSAGE_ELEMENT=no jbi message element
+NOT_ENOUGH_PARTS=not enough parts
+NO_JBI_PART_ELEMENT=no jbi part element
+EXPECTED_ELEMENT_IN_PART=expected element in part
+TOO_MANY_PARTS=too many parts
+ILLEGAL_JBIFAULT_FORMAT=illegal jbi fault format
+STAX_READ_EXC=stax read exception
+XML_WRITE_EXC=xml write exception
+STAX_WRITE_EXC=stax write exception
+NOT_EQUAL_ARG_NUM=The number of arguments is not equal
+NEED_JBIBINDING=BindingInfo should be a JbiBindingInfo
+NO_EXCEPTION=No exception on this message
+NO_XML_STREAM_WRITER=No XMLStreamWriter on this message
\ No newline at end of file
Propchange: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java?rev=603133&view=auto
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java (added)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java Mon Dec 10 18:54:22 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.servicemix.cxfse.interceptors;
+
+
+
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.xml.XMLConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+
+import org.apache.cxf.binding.jbi.JBIConstants;
+import org.apache.cxf.binding.jbi.interceptor.JBIWrapperOutInterceptor;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+
+
+public class WrapperOutInterceptor extends AbstractOutDatabindingInterceptor {
+
+ private static final Logger LOG = LogUtils.getL7dLogger(JBIWrapperOutInterceptor.class);
+
+ private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
+
+ public WrapperOutInterceptor() {
+ super(Phase.MARSHAL);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
+ XMLStreamWriter xmlWriter = getXMLStreamWriter(message);
+ Service service = message.getExchange().get(Service.class);
+
+ DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service, XMLStreamWriter.class);
+
+ try {
+ xmlWriter.setPrefix("jbi", JBIConstants.NS_JBI_WRAPPER);
+ xmlWriter.writeStartElement(JBIConstants.NS_JBI_WRAPPER,
+ JBIConstants.JBI_WRAPPER_MESSAGE.getLocalPart());
+ xmlWriter.writeNamespace("jbi", JBIConstants.NS_JBI_WRAPPER);
+
+ setTypeAttr(xmlWriter, message);
+ List<MessagePartInfo> parts = null;
+ if (!isRequestor(message)) {
+ parts = bop.getOutput().getMessageParts();
+ } else {
+ parts = bop.getInput().getMessageParts();
+ }
+ List<?> objs = (List<?>) message.getContent(List.class);
+ if (objs.size() < parts.size()) {
+ throw new Fault(new org.apache.cxf.common.i18n.Message(
+ "NOT_EQUAL_ARG_NUM", BUNDLE));
+ }
+ for (int idx = 0; idx < parts.size(); idx++) {
+ MessagePartInfo part = parts.get(idx);
+ Object obj = objs.get(idx);
+ if (!part.isElement()) {
+ if (part.getTypeClass() == String.class) {
+ xmlWriter.writeStartElement(JBIConstants.NS_JBI_WRAPPER,
+ JBIConstants.JBI_WRAPPER_PART.getLocalPart());
+ xmlWriter.writeCharacters(obj.toString());
+ xmlWriter.writeEndElement();
+ } else {
+ part = new MessagePartInfo(part.getName(), part.getMessageInfo());
+ part.setElement(false);
+ part.setConcreteName(JBIConstants.JBI_WRAPPER_PART);
+ dataWriter.write(obj, part, xmlWriter);
+ }
+ } else {
+ xmlWriter.writeStartElement(JBIConstants.NS_JBI_WRAPPER,
+ JBIConstants.JBI_WRAPPER_PART.getLocalPart());
+ dataWriter.write(obj, part, xmlWriter);
+ xmlWriter.writeEndElement();
+ }
+ }
+ xmlWriter.writeEndElement();
+
+ } catch (XMLStreamException e) {
+ throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
+ }
+ }
+
+ private void setTypeAttr(XMLStreamWriter xmlWriter, Message message) throws XMLStreamException {
+ BindingOperationInfo wsdlOperation = getOperation(message);
+ BindingMessageInfo wsdlMessage = isRequestor(message) ? wsdlOperation.getInput() : wsdlOperation.getOutput();
+
+ String typeNamespace = wsdlMessage.getMessageInfo().getName().getNamespaceURI();
+ if (typeNamespace == null || typeNamespace.length() == 0) {
+ throw new IllegalArgumentException("messageType namespace is null or empty");
+ }
+ xmlWriter.writeAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + "msg",
+ typeNamespace);
+ String typeLocalName = wsdlMessage.getMessageInfo().getName().getLocalPart();
+ if (typeLocalName == null || typeLocalName.length() == 0) {
+ throw new IllegalArgumentException("messageType local name is null or empty");
+ }
+ xmlWriter.writeAttribute("type", "msg" + ":" + typeLocalName);
+
+ }
+
+ protected BindingOperationInfo getOperation(Message message) {
+ BindingOperationInfo operation = message.getExchange().get(BindingOperationInfo.class);
+ if (operation == null) {
+ throw new Fault(new Exception("Operation not bound on this message"));
+ }
+ return operation;
+ }
+
+ protected boolean isRequestor(org.apache.cxf.message.Message message) {
+ return Boolean.TRUE.equals(message.containsKey(
+ org.apache.cxf.message.Message.REQUESTOR_ROLE));
+ }
+
+}
Propchange: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/interceptors/WrapperOutInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeSpringTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeSpringTest.java?rev=603133&r1=603132&r2=603133&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeSpringTest.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeSpringTest.java Mon Dec 10 18:54:22 2007
@@ -46,7 +46,7 @@
public void testCalculator() throws Exception {
io.getInMessage().setContent(new StringSource(
- "<message xmlns='http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper'>"
+ "<message xmlns=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\">"
+ " <part>"
+ " <add xmlns='http://apache.org/cxf/calculator/types'>"
+ " <arg0>1</arg0>"
@@ -55,7 +55,12 @@
+ " </part>"
+ "</message>"));
client.sendSync(io);
- System.err.println(new SourceTransformer().contentToString(io.getOutMessage()));
+ //the return message should have type as well
+
+ assertTrue(new SourceTransformer().contentToString(
+ io.getOutMessage()).indexOf("type=\"msg:addResponse\"") >= 0);
+ assertTrue(new SourceTransformer().contentToString(
+ io.getOutMessage()).indexOf("xmlns:msg=\"http://apache.org/cxf/calculator\"") >= 0);
}