Author: ffang
Date: Wed Jun 18 21:31:07 2008
New Revision: 669383
URL: http://svn.apache.org/viewvc?rev=669383&view=rev
Log:
[SM-1400]cxf bc consumer should be able to retrieve wsdl from internal endpoint
of JBI bus if there is one
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
(with props)
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
(with props)
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java?rev=669383&r1=669382&r2=669383&view=diff
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
(original)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
Wed Jun 18 21:31:07 2008
@@ -16,6 +16,7 @@
*/
package org.apache.servicemix.cxfbc;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -26,22 +27,24 @@
import java.util.concurrent.CopyOnWriteArrayList;
import javax.activation.DataHandler;
+import javax.jbi.JBIException;
import javax.jbi.component.ComponentContext;
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
import javax.wsdl.WSDLException;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.extensions.soap.SOAPBinding;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
+import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
-import com.ibm.wsdl.Constants;
import org.apache.cxf.Bus;
import org.apache.cxf.attachment.AttachmentImpl;
import org.apache.cxf.binding.AbstractBindingFactory;
@@ -95,6 +98,7 @@
import org.apache.servicemix.soap.util.DomUtil;
import org.springframework.core.io.Resource;
+
/**
*
* @author gnodet
@@ -212,23 +216,8 @@
public void validate() throws DeploymentException {
try {
if (definition == null) {
- if (wsdl == null) {
- throw new DeploymentException("wsdl property must be set");
- }
- description = DomUtil.parse(wsdl.getInputStream());
- WSDLFactory wsdlFactory = WSDLFactory.newInstance();
- WSDLReader reader = wsdlFactory.newWSDLReader();
- reader.setFeature(Constants.FEATURE_VERBOSE, false);
- // definition = reader.readWSDL(wsdl.getURL().toString(),
- // description);
- try {
- // use wsdl manager to parse wsdl or get cached definition
- definition = getBus().getExtension(WSDLManager.class)
- .getDefinition(wsdl.getURL());
- } catch (WSDLException ex) {
- // throw new ServiceConstructionException(new
- // Message("SERVICE_CREATION_MSG", LOG), ex);
- }
+
+ retrieveWSDL();
}
if (service == null) {
// looking for the servicename according to targetServiceName
@@ -242,6 +231,7 @@
}
WSDLServiceFactory factory = new WSDLServiceFactory(getBus(),
definition, service);
+
Service cxfService = factory.create();
EndpointInfo ei = cxfService.getServiceInfos().iterator().next()
@@ -301,6 +291,7 @@
cxfService.getOutFaultInterceptors().add(
new SoapOutInterceptor(getBus()));
+
ep = new EndpointImpl(getBus(), cxfService, ei);
getInInterceptors().addAll(getBus().getInInterceptors());
getInFaultInterceptors().addAll(getBus().getInFaultInterceptors());
@@ -344,6 +335,53 @@
}
}
+ private void retrieveWSDL() throws JBIException, WSDLException,
DeploymentException, IOException {
+ if (wsdl == null) {
+ if (getTargetService() != null && getTargetEndpoint() != null) {
+ ServiceEndpoint serviceEndpoint
+ =
getServiceUnit().getComponent().getComponentContext().getEndpoint(getTargetService(),
getTargetEndpoint());
+ if (serviceEndpoint != null) {
+ description =
+
this.getServiceUnit().getComponent().getComponentContext().getEndpointDescriptor(serviceEndpoint);
+ definition = getBus().getExtension(WSDLManager.class)
+ .getDefinition((Element)description.getFirstChild());
+ List address =
definition.getService(getTargetService()).getPort(getTargetEndpoint()).getExtensibilityElements();
+ if (address == null || address.size() == 0) {
+ SOAPAddressImpl soapAddress = new SOAPAddressImpl();
+ //specify default transport if there is no one in the
internal wsdl
+ soapAddress.setLocationURI("http://localhost");
+
definition.getService(getTargetService()).getPort(getTargetEndpoint()).addExtensibilityElement(soapAddress);
+ }
+ List binding =
definition.getService(getTargetService()).getPort(
+
getTargetEndpoint()).getBinding().getExtensibilityElements();
+ if (binding == null || binding.size() == 0) {
+ //no binding info in the internal wsdl so we need add
default soap11 binding
+ SOAPBinding soapBinding = new SOAPBindingImpl();
+
soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+ soapBinding.setStyle("document");
+
definition.getService(getTargetService()).getPort(getTargetEndpoint()).getBinding().
+ addExtensibilityElement(soapBinding);
+ }
+
+ }
+ } else {
+ throw new DeploymentException("can't get wsdl");
+ }
+
+ } else {
+ description = DomUtil.parse(wsdl.getInputStream());
+ try {
+ // use wsdl manager to parse wsdl or get cached
+ // definition
+ definition = getBus().getExtension(WSDLManager.class)
+ .getDefinition(wsdl.getURL());
+ } catch (WSDLException ex) {
+ // throw new ServiceConstructionException(new
+ // Message("SERVICE_CREATION_MSG", LOG), ex);
+ }
+ }
+ }
+
protected Bus getBus() {
if (getBusCfg() != null) {
if (bus == null) {
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java?rev=669383&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
Wed Jun 18 21:31:07 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.cxfbc;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.soap.SOAPBinding;
+
+
+import org.apache.cxf.calculator.AddNumbersFault;
+import org.apache.cxf.calculator.CalculatorPortType;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+
+public class CxfBcRetrieveWsdlFromInternalEndpointTest extends
SpringTestSupport {
+
+ private CxfBcComponent component;
+
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ component = new CxfBcComponent();
+ jbi.activateComponent(component, "CxfBcComponent");
+ CxfBcConsumer cxfBcConsumer = new CxfBcConsumer();
+ cxfBcConsumer.setTargetEndpoint("CalculatorPort");
+ cxfBcConsumer.setTargetService(new
QName("http://apache.org/cxf/calculator", "CalculatorService"));
+
cxfBcConsumer.setLocationURI("http://localhost:9000/CalculatorService/SoapPort");
+ component.addEndpoint(cxfBcConsumer);
+ component.start();
+ }
+
+ protected void tearDown() throws Exception {
+
+ }
+
+ public void testRetrieveWsdlFromIntermalEndpoint() throws Exception {
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.getInInterceptors().add(new LoggingInInterceptor());
+ factory.getOutInterceptors().add(new LoggingOutInterceptor());
+ factory.setServiceClass(CalculatorPortType.class);
+ factory.setBindingId(SOAPBinding.SOAP11HTTP_BINDING);
+ factory.setAddress("http://localhost:9000/CalculatorService/SoapPort");
+ CalculatorPortType port = (CalculatorPortType) factory.create();
+
+ int ret = port.add(1, 2);
+ assertEquals(ret, 3);
+ try {
+ port.add(1, -2);
+ fail("should get exception since there is a negative arg");
+ } catch (AddNumbersFault e) {
+ assertEquals(e.getFaultInfo().getMessage(),
+ "Negative number cant be added!");
+ }
+ }
+ @Override
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new
ClassPathXmlApplicationContext("org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml");
+ }
+
+}
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcRetrieveWsdlFromInternalEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml?rev=669383&view=auto
==============================================================================
---
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
(added)
+++
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
Wed Jun 18 21:31:07 2008
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
+ xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
+ xmlns:test="urn:test"
+ xmlns:calculator="http://apache.org/cxf/calculator">
+
+ <sm:container id="jbi" embedded="true" singleton="true">
+
+ <sm:endpoints>
+ <cxfse:endpoint>
+ <cxfse:pojo>
+ <bean class="org.apache.cxf.calculator.CalculatorImpl" />
+ </cxfse:pojo>
+ <cxfse:inInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inInterceptors>
+ <cxfse:outInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outInterceptors>
+ <cxfse:inFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inFaultInterceptors>
+ <cxfse:outFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outFaultInterceptors>
+ </cxfse:endpoint>
+ </sm:endpoints>
+
+ </sm:container>
+
+
+</beans>
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/xbean_retrieve_wsdl_from_internal_wsdl.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml