Author: alessio.soldano(a)jboss.com
Date: 2009-01-13 13:25:02 -0500 (Tue, 13 Jan 2009)
New Revision: 9025
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/CommonBindingProvider.java
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
stack/native/branches/jaxws21/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java
Log:
[JBWS-2452] Implementing getEndpointReference methods in EndpointImpl
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/CommonBindingProvider.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/CommonBindingProvider.java 2009-01-13
17:31:35 UTC (rev 9024)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/CommonBindingProvider.java 2009-01-13
18:25:02 UTC (rev 9025)
@@ -123,10 +123,17 @@
throw new UnsupportedOperationException("Cannot get epr for BindingProvider
instances using the XML/HTTP binding");
}
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
- builder.address(epMetaData.getEndpointAddress());
- builder.serviceName(epMetaData.getServiceMetaData().getServiceName());
- builder.endpointName(epMetaData.getPortName());
- builder.wsdlDocumentLocation(epMetaData.getEndpointAddress() + "?wsdl");
+ if (epMetaData != null)
+ {
+ builder.address(epMetaData.getEndpointAddress());
+ builder.serviceName(epMetaData.getServiceMetaData().getServiceName());
+ builder.endpointName(epMetaData.getPortName());
+ builder.wsdlDocumentLocation(epMetaData.getEndpointAddress() +
"?wsdl");
+ }
+ else
+ {
+ log.warn("Cannot get endpoint reference info from endpoint
metadata!");
+ }
return EndpointReferenceUtil.transform(clazz, builder.build());
}
Modified:
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
===================================================================
---
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2009-01-13
17:31:35 UTC (rev 9024)
+++
stack/native/branches/jaxws21/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2009-01-13
18:25:02 UTC (rev 9025)
@@ -21,30 +21,36 @@
*/
package org.jboss.ws.core.jaxws.spi;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.concurrent.Executor;
+
+import javax.xml.transform.Source;
+import javax.xml.ws.Binding;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServicePermission;
+import javax.xml.ws.http.HTTPBinding;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
+
import org.jboss.logging.Logger;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.core.jaxws.binding.BindingProviderImpl;
+import org.jboss.ws.core.jaxws.binding.EndpointReferenceUtil;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.http.HttpContext;
import org.jboss.wsf.spi.http.HttpServer;
import org.jboss.wsf.spi.http.HttpServerFactory;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.spi.management.ServerConfigFactory;
import org.w3c.dom.Element;
-import javax.xml.transform.Source;
-import javax.xml.ws.Binding;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Endpoint;
-import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServicePermission;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.concurrent.Executor;
-
/**
* A Web service endpoint implementation.
*
@@ -62,11 +68,12 @@
private Object implementor;
private Executor executor;
private List<Source> metadata;
- private BindingProvider bindingProvider;
+ private BindingProviderImpl bindingProvider;
private Map<String, Object> properties = new HashMap<String, Object>();
private HttpContext serverContext;
private boolean isPublished;
private boolean isDestroyed;
+ private URI address;
public EndpointImpl(String bindingId, Object implementor)
{
@@ -99,18 +106,17 @@
* @param address specifying the address to use. The address must be compatible with
the binding specified at the time the endpoint was created.
*/
@Override
- public void publish(String address)
+ public void publish(String addr)
{
- log.debug("publish: " + address);
+ log.debug("publish: " + addr);
- URI addrURI;
try
{
- addrURI = new URI(address);
+ this.address = new URI(addr);
}
catch (URISyntaxException e)
{
- throw new IllegalArgumentException("Invalid address: " + address);
+ throw new IllegalArgumentException("Invalid address: " + addr);
}
// Check with the security manger
@@ -122,7 +128,7 @@
httpServer.setProperties(properties);
httpServer.start();
- String path = addrURI.getPath();
+ String path = address.getPath();
String contextRoot = "/" + new StringTokenizer(path,
"/").nextToken();
HttpContext context = httpServer.createContext(contextRoot);
@@ -168,11 +174,30 @@
if (context instanceof HttpContext)
{
serverContext = (HttpContext)context;
+ address = getAddressFromConfigAndContext(serverContext);
HttpServer httpServer = serverContext.getHttpServer();
httpServer.publish(serverContext, this);
isPublished = true;
}
}
+
+ private static URI getAddressFromConfigAndContext(HttpContext context)
+ {
+ try
+ {
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServerConfigFactory spi = provider.getSPI(ServerConfigFactory.class);
+ ServerConfig serverConfig = spi.getServerConfig();
+ String host = serverConfig.getWebServiceHost();
+ int port = serverConfig.getWebServicePort();
+ String hostAndPort = host + (port > 0 ? ":" + port : "");
+ return new URI("http://" + hostAndPort + context.getContextRoot());
+ }
+ catch (URISyntaxException e)
+ {
+ throw new WebServiceException("Error while getting endpoint address from
context!", e);
+ }
+ }
@Override
public void stop()
@@ -261,12 +286,27 @@
@Override
public EndpointReference getEndpointReference(Element... referenceParameters)
{
- throw new NotImplementedException();
+ return getEndpointReference(W3CEndpointReference.class, referenceParameters);
}
@Override
public <T extends EndpointReference> T getEndpointReference(Class<T>
clazz, Element... referenceParameters)
{
- throw new NotImplementedException();
+ if (isDestroyed || !isPublished)
+ throw new WebServiceException("Cannot get EPR for an unpubblished or
already destroyed endpoint!");
+ if (getBinding() instanceof HTTPBinding )
+ {
+ throw new UnsupportedOperationException("Cannot get epr when using the
XML/HTTP binding");
+ }
+ W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
+ builder.address(address.toString());
+ builder.wsdlDocumentLocation(address.toString() + "?wsdl");
+ //TODO set other parameters in the builder
+ if (referenceParameters != null &&
W3CEndpointReference.class.getName().equals(clazz.getName()))
+ {
+ for (Element el : referenceParameters)
+ builder.referenceParameter(el);
+ }
+ return EndpointReferenceUtil.transform(clazz, builder.build());
}
}
Modified:
stack/native/branches/jaxws21/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java
===================================================================
---
stack/native/branches/jaxws21/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java 2009-01-13
17:31:35 UTC (rev 9024)
+++
stack/native/branches/jaxws21/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java 2009-01-13
18:25:02 UTC (rev 9025)
@@ -32,14 +32,20 @@
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import javax.xml.ws.Endpoint;
+import javax.xml.ws.EndpointReference;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+import org.jboss.logging.Logger;
+import org.jboss.wsf.common.DOMUtils;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.http.HttpContext;
import org.jboss.wsf.spi.http.HttpServer;
import org.jboss.wsf.spi.http.HttpServerFactory;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* Test Endpoint deployment
@@ -50,6 +56,7 @@
public class EndpointServlet extends HttpServlet
{
private Endpoint endpoint;
+ private static final String TEST_ELEMENT = "<fabrikam:CustomerKey
xmlns:fabrikam='http://example.com/fabrikam'>123456789</fab...;
@Override
public void init(ServletConfig config) throws ServletException
@@ -90,9 +97,32 @@
// Invoke the endpoint
String param = req.getParameter("param");
String retStr = port.echo(param);
+
+ //Test epr
+
assertEndpointReference(endpoint.getEndpointReference(DOMUtils.parse(TEST_ELEMENT)),
TEST_ELEMENT);
+ assertEndpointReference(endpoint.getEndpointReference(W3CEndpointReference.class,
(Element[])null), null);
// Return the result
PrintWriter pw = new PrintWriter(res.getWriter());
pw.print(retStr);
}
+
+
+
+ private void assertEndpointReference(EndpointReference epr, String refPar) throws
IOException
+ {
+ Logger.getLogger(this.getClass()).info("epr: "+epr);
+ assert(W3CEndpointReference.class.getName().equals(epr.getClass().getName()));
+ Element endpointReference = DOMUtils.parse(epr.toString());
+ assert("EndpointReference".equals(endpointReference.getNodeName()));
+
assert("http://www.w3.org/2005/08/addressing".equals(endpointRe...;
+ NodeList addresses = endpointReference.getElementsByTagName("Address");
+ assert(addresses.getLength() == 1);
+
assert("http://127.0.0.1:8080/jaxws-endpoint".equals(addresses.item(0).getFirstChild().getNodeValue()));
+ if (refPar != null)
+ {
+ //TODO enhance this check
+ assert(epr.toString().contains(refPar));
+ }
+ }
}