[
https://issues.apache.org/jira/browse/CAMEL-12714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16572842#comment-16572842
]
ASF GitHub Bot commented on CAMEL-12714:
----------------------------------------
davsclaus closed pull request #2457: CAMEL-12714 - support handlers in cxf
payload mode without SEI
URL: https://github.com/apache/camel/pull/2457
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
index 58051c2723f..8f521e74ad5 100644
---
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
+++
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
@@ -439,7 +439,7 @@ protected void initializeAnnotationInterceptors(Endpoint
ep, Class<?> cls) {
protected void setupHandlers(ClientFactoryBean factoryBean, Client client)
throws Exception {
- if (factoryBean instanceof JaxWsClientFactoryBean && handlers != null)
{
+ if (handlers != null) {
AnnotationHandlerChainBuilder
builder = new AnnotationHandlerChainBuilder();
Method m = factoryBean.getClass().getMethod("getServiceFactory");
@@ -629,28 +629,28 @@ Client createClient() throws Exception {
}
}
- Class<?> cls = null;
- if (getServiceClass() != null) {
- cls = getServiceClass();
+ Class<?> cls = getServiceClass();
+ ClientFactoryBean factoryBean;
+ if (cls != null) {
// create client factory bean
- ClientFactoryBean factoryBean = createClientFactoryBean(cls);
- // setup client factory bean
- setupClientFactoryBean(factoryBean, cls);
- Client client = factoryBean.create();
- // setup the handlers
- setupHandlers(factoryBean, client);
- return client;
+ factoryBean = createClientFactoryBean(cls);
} else {
- // create the client without service class
-
- checkName(getPortName(), "endpoint/port name");
- checkName(getServiceName(), "service name");
-
- ClientFactoryBean factoryBean = createClientFactoryBean();
- // setup client factory bean
- setupClientFactoryBean(factoryBean, null);
- return factoryBean.create();
+ factoryBean = createClientFactoryBean();
+ }
+
+ // setup client factory bean
+ setupClientFactoryBean(factoryBean, cls);
+
+ if (cls == null) {
+ checkName(factoryBean.getEndpointName(), "endpoint/port name");
+ checkName(factoryBean.getServiceName(), "service name");
}
+
+ Client client = factoryBean.create();
+
+ // setup the handlers
+ setupHandlers(factoryBean, client);
+ return client;
}
void checkName(Object value, String name) {
@@ -688,11 +688,7 @@ ServerFactoryBean createServerFactoryBean() throws
Exception {
if (cls == null) {
checkName(portName, " endpoint/port name");
checkName(serviceName, " service name");
- answer = new JaxWsServerFactoryBean(new WSDLServiceFactoryBean()) {
- {
- doInit = false;
- }
- };
+ answer = new JaxWsServerFactoryBean(new WSDLServiceFactoryBean());
cls = Provider.class;
} else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
answer = new JaxWsServerFactoryBean();
diff --git
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
index cc676606b6f..0671b1632cd 100644
---
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
+++
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
@@ -47,23 +47,6 @@ public CxfSpringEndpoint(CxfComponent component, String
address) throws Exceptio
public CxfSpringEndpoint() {
}
- /**
- *
- * A help to get the service class. The serviceClass classname in URI
- * query takes precedence over the serviceClass in CxfEndpointBean.
- */
- private Class<?> getSEIClass() throws ClassNotFoundException {
-
- // get service class
- Class<?> answer = null;
- if (getServiceClass() != null) {
- // classname is specified in URI which overrides the bean
properties
- answer = getServiceClass();
- }
- return answer;
- }
-
-
// Package private methods
//
-------------------------------------------------------------------------
@@ -74,7 +57,7 @@ public CxfSpringEndpoint() {
Client createClient() throws Exception {
// get service class
- Class<?> cls = getSEIClass();
+ Class<?> cls = getServiceClass();
if (getDataFormat().equals(DataFormat.POJO)) {
ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
@@ -88,61 +71,44 @@ Client createClient() throws Exception {
if (getDataFormat().equals(DataFormat.PAYLOAD)) {
setSkipPayloadMessagePartCheck(true);
}
- cls = getSEIClass();
+ cls = getServiceClass();
}
+ ClientFactoryBean factoryBean;
if (cls != null) {
// create client factory bean
- ClientFactoryBean factoryBean = createClientFactoryBean(cls);
-
- // setup client factory bean
- setupClientFactoryBean(factoryBean, cls);
-
- // fill in values that have not been filled.
- QName serviceQName = null;
- try {
- serviceQName = factoryBean.getServiceName();
- } catch (IllegalStateException e) {
- // It throws IllegalStateException if serviceName has not been
set.
- }
+ factoryBean = createClientFactoryBean(cls);
+ } else {
+ factoryBean = createClientFactoryBean();
+ }
- if (serviceQName == null && getServiceLocalName() != null) {
- factoryBean.setServiceName(new QName(getServiceNamespace(),
getServiceLocalName()));
- }
- if (factoryBean.getEndpointName() == null &&
getEndpointLocalName() != null) {
- factoryBean.setEndpointName(new QName(getEndpointNamespace(),
getEndpointLocalName()));
- }
+ // setup client factory bean
+ setupClientFactoryBean(factoryBean, cls);
- Client client = factoryBean.create();
- // setup the handlers
- setupHandlers(factoryBean, client);
- return client;
- } else {
-
- ClientFactoryBean factoryBean = createClientFactoryBean();
+ // fill in values that have not been filled.
+ QName serviceQName = null;
+ try {
+ serviceQName = factoryBean.getServiceName();
+ } catch (IllegalStateException e) {
+ // It throws IllegalStateException if serviceName has not been set.
+ }
- // setup client factory bean
- setupClientFactoryBean(factoryBean, null);
-
- // fill in values that have not been filled.
- QName serviceQName = null;
- try {
- serviceQName = factoryBean.getServiceName();
- } catch (IllegalStateException e) {
- // It throws IllegalStateException if serviceName has not been
set.
- }
-
- if (serviceQName == null && getServiceLocalName() != null) {
- factoryBean.setServiceName(new QName(getServiceNamespace(),
getServiceLocalName()));
- }
- if (factoryBean.getEndpointName() == null &&
getEndpointLocalName() != null) {
- factoryBean.setEndpointName(new QName(getEndpointNamespace(),
getEndpointLocalName()));
- }
-
+ if (serviceQName == null && getServiceLocalName() != null) {
+ factoryBean.setServiceName(new QName(getServiceNamespace(),
getServiceLocalName()));
+ }
+ if (factoryBean.getEndpointName() == null && getEndpointLocalName() !=
null) {
+ factoryBean.setEndpointName(new QName(getEndpointNamespace(),
getEndpointLocalName()));
+ }
+
+ if (cls == null) {
checkName(factoryBean.getEndpointName(), "endpoint/port name");
checkName(factoryBean.getServiceName(), "service name");
- return factoryBean.create();
}
+
+ Client client = factoryBean.create();
+ // setup the handlers
+ setupHandlers(factoryBean, client);
+ return client;
}
@@ -153,7 +119,7 @@ Client createClient() throws Exception {
ServerFactoryBean createServerFactoryBean() throws Exception {
// get service class
- Class<?> cls = getSEIClass();
+ Class<?> cls = getServiceClass();
if (getWsdlURL() == null && cls == null) {
// no WSDL and serviceClass specified, set our default serviceClass
@@ -170,11 +136,7 @@ ServerFactoryBean createServerFactoryBean() throws
Exception {
if (cls == null) {
if (!getDataFormat().equals(DataFormat.POJO)) {
- answer = new JaxWsServerFactoryBean(new
WSDLServiceFactoryBean()) {
- {
- doInit = false;
- }
- };
+ answer = new JaxWsServerFactoryBean(new
WSDLServiceFactoryBean());
cls = Provider.class;
} else {
ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
diff --git
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
index 4b5d1b24f21..254d99701ee 100644
---
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
+++
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
@@ -26,8 +26,8 @@
import org.apache.camel.RuntimeCamelException;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.EndpointException;
-import org.apache.cxf.endpoint.EndpointImpl;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.apache.cxf.service.factory.FactoryBeanListener.Event;
import org.apache.cxf.service.invoker.Invoker;
@@ -102,7 +102,7 @@ protected void buildServiceFromWSDL(String url) {
super.buildServiceFromWSDL(url);
}
public Endpoint createEndpoint(EndpointInfo ei) throws EndpointException {
- Endpoint ep = new EndpointImpl(getBus(), getService(), ei);
+ Endpoint ep = new JaxWsEndpointImpl(getBus(), getService(), ei);
sendEvent(Event.ENDPOINT_CREATED, ei, ep, getServiceClass());
return ep;
}
diff --git
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEITest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEITest.java
new file mode 100644
index 00000000000..da19e09fb2b
--- /dev/null
+++
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEITest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.camel.component.cxf;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.wsdl_first.PersonImpl;
+import org.apache.cxf.binding.soap.SoapFault;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfPayloadWsdlWithoutSEITest extends AbstractCxfWsdlFirstTest {
+
+ @BeforeClass
+ public static void startService() {
+ Object implementor = new PersonImpl();
+ String address = "http://localhost:" + getPort1() +
"/CxfPayloadWsdlWithoutSEITest/PersonService/";
+ Endpoint.publish(address, implementor);
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEI.xml");
+ }
+
+ @Test
+ @Override
+ public void testInvokingServiceWithCamelProducer() {
+ Exchange exchange = sendJaxWsMessage("hello");
+ assertEquals("The request should be handled sucessfully ",
exchange.isFailed(), false);
+ org.apache.camel.Message out = exchange.getOut();
+ String result = out.getBody(String.class);
+ assertStringContains(result, "Bonjour");
+
+ exchange = sendJaxWsMessage("");
+ assertEquals("We should get a fault here", exchange.isFailed(), true);
+ Throwable ex = exchange.getException();
+ assertTrue("We should get a SoapFault here", ex instanceof SoapFault);
+ }
+
+ private Exchange sendJaxWsMessage(final String personIdString) {
+ Exchange exchange = template.send("direct:producer", new Processor() {
+ public void process(final Exchange exchange) {
+ String body = "<GetPerson
xmlns=\"http://camel.apache.org/wsdl-first/types\"><personId>" + personIdString
+ "</personId></GetPerson>\n";
+ exchange.getIn().setBody(body);
+ exchange.getIn().setHeader(CxfConstants.OPERATION_NAME,
"GetPerson");
+ }
+ });
+ return exchange;
+ }
+
+}
diff --git
a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEI.xml
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEI.xml
new file mode 100644
index 00000000000..fa60edd2837
--- /dev/null
+++
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfPayloadWsdlWithoutSEI.xml
@@ -0,0 +1,55 @@
+<?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="http://www.springframework.org/schema/beans"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd ">
+
+ <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <cxf:cxfEndpoint
+
address="http://localhost:${CXFTestSupport.port2}/CxfPayloadWsdlWithoutSEITest/PersonService/"
+ endpointName="person:soap" id="routerEndpoint"
+ serviceName="person:PersonService"
+ wsdlURL="classpath:person.wsdl"
xmlns:person="http://camel.apache.org/wsdl-first">
+ <cxf:properties>
+ <entry key="schema-validation-enabled" value="true"/>
+ </cxf:properties>
+ <cxf:handlers>
+ <ref bean="fromEndpointJaxwsHandler"/>
+ </cxf:handlers>
+ </cxf:cxfEndpoint>
+
+ <cxf:cxfEndpoint
+
address="http://localhost:${CXFTestSupport.port1}/CxfPayloadWsdlWithoutSEITest/PersonService/"
+ endpointName="person:soap" id="serviceEndpoint"
+ serviceName="person:PersonService"
xmlns:person="http://camel.apache.org/wsdl-first"
+ wsdlURL="classpath:person.wsdl">
+ <cxf:handlers>
+ <ref bean="toEndpointJaxwsHandler"/>
+ </cxf:handlers>
+ </cxf:cxfEndpoint>
+
+ <bean class="org.apache.camel.builder.NoErrorHandlerBuilder"
id="noErrorHandler"/>
+
+ <bean class="org.apache.camel.wsdl_first.JaxwsTestHandler"
id="fromEndpointJaxwsHandler"/>
+ <bean class="org.apache.camel.wsdl_first.JaxwsTestHandler"
id="toEndpointJaxwsHandler"/>
+
+ <camelContext errorHandlerRef="noErrorHandler" id="camel"
xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint?dataFormat=PAYLOAD"/>
+ <to uri="cxf:bean:serviceEndpoint?dataFormat=PAYLOAD"/>
+ </route>
+ <route>
+ <from uri="direct:producer"/>
+ <to uri="cxf:bean:serviceEndpoint?dataFormat=PAYLOAD"/>
+ </route>
+ </camelContext>
+
+</beans>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> support handlers in cxf payload data format without SEI
> -------------------------------------------------------
>
> Key: CAMEL-12714
> URL: https://issues.apache.org/jira/browse/CAMEL-12714
> Project: Camel
> Issue Type: Improvement
> Components: camel-cxf
> Reporter: Peter Van den Bosch
> Priority: Major
>
> When using a cxf endpoint in payload mode, specifying a WSDL and no service
> class, the JAX-WS protocol handlers are ignored.
> Documentation however indicates that payload mode supports protocol JAX-WS
> handlers.
> I made a pull request that activates the JAX-WS handlers in this scenario as
> well, by using a JaxWsEndpointImpl instead of EndpointImpl and removing some
> checks that avoid the handlers being set.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)