You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/04/08 20:29:57 UTC
svn commit: r1465713 - in
/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src:
main/java/org/apache/cxf/ws/discovery/
main/java/org/apache/cxf/ws/discovery/internal/
test/java/org/apache/cxf/ws/discovery/
Author: dkulp
Date: Mon Apr 8 18:29:57 2013
New Revision: 1465713
URL: http://svn.apache.org/r1465713
Log:
Merged revisions 1465708 via git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1465708 | dkulp | 2013-04-08 14:26:52 -0400 (Mon, 08 Apr 2013) | 5 lines
Bunch of updates to WS-Discovery
1) Start supporting WS-Discovery 1.0 namespaces on client side
2) Fix problems with the WSA Action being wrong
3) Return and action from the service
........
Added:
cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
Modified:
cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
Added: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java?rev=1465713&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java (added)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java Mon Apr 8 18:29:57 2013
@@ -0,0 +1,136 @@
+/**
+ * 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.ws.discovery;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.apache.cxf.feature.StaxTransformFeature;
+import org.apache.cxf.jaxws.DispatchImpl;
+
+public abstract class WSDVersion {
+ public static final String NS_1_0 = "http://schemas.xmlsoap.org/ws/2005/04/discovery";
+ public static final String TO_1_0 = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
+
+ public static final String NS_1_1 = "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01";
+ public static final String TO_1_1 = "urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01";
+
+ public static final WSDVersion INSTANCE_1_0 = new WSDVersion10();
+ public static final WSDVersion INSTANCE_1_1 = new WSDVersion11();
+
+ abstract String getNamespace();
+ abstract String getToAddress();
+ abstract String getAddressingNamespace();
+ abstract void addVersionTransformer(Dispatch<Object> dispatch);
+ abstract QName getServiceName();
+ abstract String getSoapVersion();
+
+ public String getHelloAction() {
+ return getNamespace() + "/Hello";
+ }
+ public String getByeAction() {
+ return getNamespace() + "/Bye";
+ }
+ public String getProbeAction() {
+ return getNamespace() + "/Probe";
+ }
+
+ static final class WSDVersion10 extends WSDVersion {
+ static final WSDVersion10 INSTANCE = new WSDVersion10();
+
+ private WSDVersion10() {
+ }
+ public String getNamespace() {
+ return NS_1_0;
+ }
+
+ public String getToAddress() {
+ return TO_1_0;
+ }
+
+ public String getAddressingNamespace() {
+ return "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+ }
+ public void addVersionTransformer(Dispatch<Object> dispatch) {
+ StaxTransformFeature feature = new StaxTransformFeature();
+ Map<String, String> outElements = new HashMap<String, String>();
+ outElements.put("{" + NS_1_1 + "}*",
+ "{" + NS_1_0 + "}*");
+ outElements.put("{" + INSTANCE_1_1.getAddressingNamespace() + "}*",
+ "{" + getAddressingNamespace() + "}*");
+ feature.setOutTransformElements(outElements);
+
+ Map<String, String> inElements = new HashMap<String, String>();
+ inElements.put("{" + NS_1_0 + "}*",
+ "{" + NS_1_1 + "}*");
+ inElements.put("{" + getAddressingNamespace() + "}*",
+ "{" + INSTANCE_1_1.getAddressingNamespace() + "}*");
+ feature.setInTransformElements(inElements);
+
+ feature.initialize(((DispatchImpl)dispatch).getClient(),
+ ((DispatchImpl)dispatch).getClient().getBus());
+
+ Map<String, String> nsMap = new HashMap<String, String>();
+ nsMap.put("tns", NS_1_0);
+ nsMap.put("wsa", getAddressingNamespace());
+ ((DispatchImpl)dispatch).getClient().getEndpoint().getEndpointInfo()
+ .setProperty("soap.env.ns.map", nsMap);
+ }
+ public QName getServiceName() {
+ return new QName(NS_1_0, "DiscoveryProxy");
+ }
+ public String getSoapVersion() {
+ return SOAPBinding.SOAP11HTTP_BINDING;
+ }
+ }
+ static final class WSDVersion11 extends WSDVersion {
+ private WSDVersion11() {
+ }
+
+ public String getNamespace() {
+ return NS_1_1;
+ }
+
+ public String getToAddress() {
+ return TO_1_1;
+ }
+
+ public String getAddressingNamespace() {
+ return "http://www.w3.org/2005/08/addressing";
+ }
+ public void addVersionTransformer(Dispatch<Object> dispatch) {
+ Map<String, String> nsMap = new HashMap<String, String>();
+ nsMap.put("tns", NS_1_1);
+ nsMap.put("wsa", getAddressingNamespace());
+ ((DispatchImpl)dispatch).getClient().getEndpoint().getEndpointInfo()
+ .setProperty("soap.env.ns.map", nsMap);
+ }
+ public QName getServiceName() {
+ return new QName(NS_1_1, "DiscoveryProxy");
+ }
+ public String getSoapVersion() {
+ return SOAPBinding.SOAP12HTTP_BINDING;
+ }
+ }
+
+}
\ No newline at end of file
Modified: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java?rev=1465713&r1=1465712&r2=1465713&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java (original)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java Mon Apr 8 18:29:57 2013
@@ -40,7 +40,6 @@ import javax.xml.ws.EndpointReference;
import javax.xml.ws.Response;
import javax.xml.ws.Service;
import javax.xml.ws.soap.AddressingFeature;
-import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
@@ -50,6 +49,7 @@ import org.apache.cxf.common.jaxb.JAXBCo
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.headers.Header;
import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.ServiceImpl;
import org.apache.cxf.jaxws.spi.ProviderImpl;
import org.apache.cxf.ws.addressing.AddressingProperties;
import org.apache.cxf.ws.addressing.AttributedURIType;
@@ -71,26 +71,35 @@ import org.apache.cxf.wsdl.EndpointRefer
*
*/
public class WSDiscoveryClient implements Closeable {
- public static final QName SERVICE_QNAME
- = new QName("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", "DiscoveryProxy");
+
+ public static final QName SERVICE_QNAME = new QName(WSDVersion.NS_1_1, "DiscoveryProxy");
+
+
String address = "soap.udp://239.255.255.250:3702";
boolean adHoc = true;
AtomicInteger msgId = new AtomicInteger(1);
long instanceId = System.currentTimeMillis();
JAXBContext jaxbContext;
- Service service;
+ ServiceImpl service;
Dispatch<Object> dispatch;
ObjectFactory factory = new ObjectFactory();
- Bus bus;
+ final Bus bus;
int defaultProbeTimeout = 1000;
+ WSDVersion version = WSDVersion.INSTANCE_1_1;
public WSDiscoveryClient() {
+ this((Bus)null);
}
- public WSDiscoveryClient(Bus bus) {
- this.bus = bus;
+ public WSDiscoveryClient(Bus b) {
+ this.bus = b == null ? BusFactory.getThreadDefaultBus() : b;
}
public WSDiscoveryClient(String address) {
+ this((Bus)null);
+ resetDispatch(address);
+ }
+ public WSDiscoveryClient(Bus b, String address) {
+ this(b);
resetDispatch(address);
}
@@ -110,6 +119,11 @@ public class WSDiscoveryClient implement
}
}
+ public void setVersion10() {
+ version = WSDVersion.INSTANCE_1_0;
+ service = null;
+ dispatch = null;
+ }
private synchronized JAXBContext getJAXBContext() {
if (jaxbContext == null) {
@@ -121,12 +135,15 @@ public class WSDiscoveryClient implement
}
return jaxbContext;
}
- private synchronized Service getService() {
+ private synchronized ServiceImpl getService() {
if (service == null) {
Bus b = BusFactory.getAndSetThreadDefaultBus(bus);
try {
- service = Service.create(SERVICE_QNAME);
- service.addPort(SERVICE_QNAME, SOAPBinding.SOAP12HTTP_BINDING, address);
+ service = new ServiceImpl(bus, null,
+ version.getServiceName(),
+ Service.class);
+ service.addPort(version.getServiceName(),
+ version.getSoapVersion(), address);
} finally {
BusFactory.setThreadDefaultBus(b);
}
@@ -154,27 +171,31 @@ public class WSDiscoveryClient implement
}
}
- private synchronized Dispatch<Object> getDispatchInternal(boolean addSeq) {
+ private synchronized Dispatch<Object> getDispatchInternal(boolean addSeq, String action) {
if (dispatch == null) {
AddressingFeature f = new AddressingFeature(true, true);
- dispatch = getService().createDispatch(SERVICE_QNAME, getJAXBContext(), Service.Mode.PAYLOAD, f);
+ dispatch = getService().createDispatch(version.getServiceName(), getJAXBContext(), Service.Mode.PAYLOAD, f);
dispatch.getRequestContext().put("thread.local.request.context", Boolean.TRUE);
+ version.addVersionTransformer(dispatch);
}
- addAddressing(dispatch, false);
+ addAddressing(dispatch, false, action);
return dispatch;
}
- private void addAddressing(BindingProvider p, boolean addSeq) {
+ private void addAddressing(BindingProvider p, boolean addSeq, String action) {
+ AddressingProperties addrProperties = new AddressingPropertiesImpl();
+ if (action != null) {
+ AttributedURIType act = new AttributedURIType();
+ act.setValue(action);
+ addrProperties.setAction(act);
+ }
if (adHoc) {
EndpointReferenceType to = new EndpointReferenceType();
- AddressingProperties addrProperties = new AddressingPropertiesImpl();
+ addrProperties.exposeAs(version.getAddressingNamespace());
AttributedURIType epr = new AttributedURIType();
- epr.setValue("urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01");
+ epr.setValue(version.getToAddress());
to.setAddress(epr);
addrProperties.setTo(to);
- p.getRequestContext()
- .put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
-
if (addSeq) {
AppSequenceType s = new AppSequenceType();
s.setInstanceId(instanceId);
@@ -188,7 +209,10 @@ public class WSDiscoveryClient implement
p.getRequestContext()
.put(Header.HEADER_LIST, headers);
}
+ } else {
+ addrProperties.exposeAs(version.getAddressingNamespace());
}
+ p.getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
}
public synchronized void close() throws IOException {
@@ -211,7 +235,7 @@ public class WSDiscoveryClient implement
if (hello.getEndpointReference() == null) {
hello.setEndpointReference(generateW3CEndpointReference());
}
- getDispatchInternal(true).invokeOneWay(factory.createHello(hello));
+ getDispatchInternal(true, version.getHelloAction()).invokeOneWay(factory.createHello(hello));
return hello;
}
@@ -235,7 +259,7 @@ public class WSDiscoveryClient implement
public void unregister(ByeType bye) {
- getDispatchInternal(true).invokeOneWay(factory.createBye(bye));
+ getDispatchInternal(true, version.getByeAction()).invokeOneWay(factory.createBye(bye));
}
public void unregister(HelloType hello) {
ByeType bt = new ByeType();
@@ -273,7 +297,7 @@ public class WSDiscoveryClient implement
return probe(params, defaultProbeTimeout);
}
public ProbeMatchesType probe(ProbeType params, int timeout) {
- Dispatch<Object> disp = this.getDispatchInternal(false);
+ Dispatch<Object> disp = this.getDispatchInternal(false, version.getProbeAction());
if (adHoc) {
disp.getRequestContext().put("udp.multi.response.timeout", timeout);
final ProbeMatchesType response = new ProbeMatchesType();
@@ -288,8 +312,9 @@ public class WSDiscoveryClient implement
response.getProbeMatch().addAll(((ProbeMatchesType)o).getProbeMatch());
} else if (o instanceof HelloType) {
HelloType h = (HelloType)o;
- if (h.getTypes().contains(SERVICE_QNAME)
- || h.getTypes().contains(new QName("", SERVICE_QNAME.getLocalPart()))) {
+ QName sn = version.getServiceName();
+ if (h.getTypes().contains(sn)
+ || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
// A DiscoveryProxy wants us to flip to managed mode
resetDispatch(h.getXAddrs().get(0));
}
Modified: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java?rev=1465713&r1=1465712&r2=1465713&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java (original)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java Mon Apr 8 18:29:57 2013
@@ -55,9 +55,14 @@ import org.apache.cxf.BusFactory;
import org.apache.cxf.common.jaxb.JAXBContextCache;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.service.model.ServiceModelUtil;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.staxutils.transform.InTransformReader;
+import org.apache.cxf.ws.addressing.AddressingProperties;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.ContextUtils;
+import org.apache.cxf.ws.addressing.impl.AddressingPropertiesImpl;
import org.apache.cxf.ws.discovery.WSDiscoveryClient;
import org.apache.cxf.ws.discovery.WSDiscoveryService;
import org.apache.cxf.ws.discovery.wsdl.ByeType;
@@ -77,7 +82,7 @@ public class WSDiscoveryServiceImpl impl
boolean started;
public WSDiscoveryServiceImpl(Bus b) {
- bus = b;
+ bus = b == null ? BusFactory.newInstance().createBus() : b;
client = new WSDiscoveryClient();
update(bus.getProperties());
}
@@ -430,6 +435,15 @@ public class WSDiscoveryServiceImpl impl
if (pmt == null) {
return null;
}
+ AddressingProperties p = ContextUtils.retrieveMAPs(PhaseInterceptorChain.getCurrentMessage(),
+ false, false);
+ AddressingProperties pout = new AddressingPropertiesImpl();
+ AttributedURIType action = new AttributedURIType();
+ action.setValue(p.getAction().getValue() + "Matches");
+ pout.exposeAs(p.getNamespaceURI());
+ pout.setAction(action);
+ ContextUtils.storeMAPs(pout, PhaseInterceptorChain.getCurrentMessage(), true);
+
if (mapToOld) {
doc.removeChild(doc.getDocumentElement());
DOMResult result = new DOMResult(doc);
@@ -440,6 +454,9 @@ public class WSDiscoveryServiceImpl impl
Map<String, String> inMap = new HashMap<String, String>();
inMap.put("{http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}*",
"{http://schemas.xmlsoap.org/ws/2005/04/discovery}*");
+
+
+
InTransformReader reader = new InTransformReader(domReader, inMap , null, false);
doc = StaxUtils.read(reader);
return new DOMSource(doc);
Modified: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java?rev=1465713&r1=1465712&r2=1465713&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java (original)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java Mon Apr 8 18:29:57 2013
@@ -23,6 +23,9 @@ import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl;
import org.apache.cxf.ws.discovery.wsdl.HelloType;
import org.apache.cxf.ws.discovery.wsdl.ProbeMatchType;
@@ -42,13 +45,18 @@ public final class WSDiscoveryClientTest
public static void main(String[] arg) throws Exception {
try {
+ Bus bus = BusFactory.getDefaultBus();
Endpoint ep = Endpoint.publish("http://localhost:51919/Foo/Snarf", new FooImpl());
- WSDiscoveryServiceImpl service = new WSDiscoveryServiceImpl(null);
+ WSDiscoveryServiceImpl service = new WSDiscoveryServiceImpl(bus);
service.startup();
+ HelloType h = service.register(ep.getEndpointReference());
+
- WSDiscoveryClient c = new WSDiscoveryClient();
- HelloType h = service.register(ep.getEndpointReference());
+ bus = BusFactory.newInstance().createBus();
+ new LoggingFeature().initialize(bus);
+ WSDiscoveryClient c = new WSDiscoveryClient(bus);
+ //c.setVersion10();
System.out.println("1");