Author: thomas.diesler(a)jboss.com
Date: 2007-10-08 05:12:20 -0400 (Mon, 08 Oct 2007)
New Revision: 4689
Added:
stack/native/branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
Modified:
stack/native/branches/tdiesler/trunk/src/main/java/javax/xml/ws/Binding21.java
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
Log:
partial commit
Modified: stack/native/branches/tdiesler/trunk/src/main/java/javax/xml/ws/Binding21.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/main/java/javax/xml/ws/Binding21.java 2007-10-07
12:05:28 UTC (rev 4688)
+++
stack/native/branches/tdiesler/trunk/src/main/java/javax/xml/ws/Binding21.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -21,6 +21,8 @@
*/
package javax.xml.ws;
+// $Id:$
+
/**
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
Modified:
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java 2007-10-07
12:05:28 UTC (rev 4688)
+++
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -21,15 +21,15 @@
*/
package org.jboss.ws.core.jaxws.binding;
+//$Id$
+
import java.util.List;
-import javax.xml.ws.Binding;
import javax.xml.ws.Binding21;
import javax.xml.ws.handler.Handler;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
-// $Id$
/**
* Extension to JAXWS protocol bindings.
@@ -39,7 +39,9 @@
*/
public interface BindingExt extends Binding21
{
+ /** Get the handler chain for a given type */
List<Handler> getHandlerChain(HandlerType handlerType);
-
+
+ /** Set the handler chain for a given type */
void setHandlerChain(List<Handler> handlerChain, HandlerType handlerType);
}
Modified:
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java 2007-10-07
12:05:28 UTC (rev 4688)
+++
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -37,7 +37,6 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.WebServiceException;
-import javax.xml.ws.wsaddressing.BindingProvider21;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.MessageContext;
@@ -47,6 +46,7 @@
import javax.xml.ws.http.HTTPException;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.SOAPFaultException;
+import javax.xml.ws.wsaddressing.BindingProvider21;
import org.jboss.logging.Logger;
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
@@ -59,11 +59,11 @@
import org.jboss.ws.core.jaxws.handler.HandlerChainExecutor;
import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
import org.jboss.ws.core.jaxws.handler.MessageContextJAXWS;
-import org.jboss.ws.core.jaxws.handler.PortInfoImpl;
import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.metadata.config.Configurable;
import org.jboss.ws.metadata.config.ConfigurationProvider;
+import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
@@ -79,22 +79,21 @@
// provide logging
private static Logger log = Logger.getLogger(ClientImpl.class);
- // the associated endpoint meta data
- private final EndpointMetaData epMetaData;
+ // the associated endpoint meta data
+ private final ClientEndpointMetaData epMetaData;
- // Keep a handle on the resolver so that updateConfig calls may revisit the associated
chains
- private final HandlerResolver handlerResolver;
-
- private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+ // Keep a handle on the resolver so that updateConfig calls may revisit the associated
chains
+ private final HandlerResolver handlerResolver;
- private static HandlerType[] HANDLER_TYPES = new HandlerType[] {HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST};
-
- public ClientImpl(EndpointMetaData epMetaData, HandlerResolver handlerResolver)
+ private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+ private static HandlerType[] HANDLER_TYPES = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+
+ public ClientImpl(EndpointMetaData epMetaData, HandlerResolver handlerResolver)
{
super(epMetaData);
setTargetEndpointAddress(epMetaData.getEndpointAddress());
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.handlerResolver = handlerResolver;
initBindingHandlerChain(false);
@@ -112,31 +111,31 @@
{
BindingExt binding = (BindingExt)getBindingProvider().getBinding();
- PortInfo portInfo = getPortInfo(epMetaData);
+ PortInfo portInfo = epMetaData.getPortInfo();
- if (handlerResolver != null)
- {
+ if (handlerResolver != null)
+ {
- boolean jbossHandlerResolver = handlerResolver instanceof HandlerResolverImpl;
-
- if (jbossHandlerResolver) // knows about PRE and POST handlers
- {
- HandlerResolverImpl impl = (HandlerResolverImpl)handlerResolver;
- impl.initHandlerChain(epMetaData, HandlerType.PRE, clearExistingHandlers);
- impl.initHandlerChain(epMetaData, HandlerType.ENDPOINT, clearExistingHandlers);
- impl.initHandlerChain(epMetaData, HandlerType.POST, clearExistingHandlers);
+ boolean jbossHandlerResolver = handlerResolver instanceof HandlerResolverImpl;
- List<Handler> preChain = impl.getHandlerChain(portInfo, HandlerType.PRE);
- List<Handler> postChain = impl.getHandlerChain(portInfo, HandlerType.POST);
-
- binding.setHandlerChain(postChain, HandlerType.POST);
- binding.setHandlerChain(preChain, HandlerType.PRE);
- }
+ if (jbossHandlerResolver) // knows about PRE and POST handlers
+ {
+ HandlerResolverImpl impl = (HandlerResolverImpl)handlerResolver;
+ impl.initHandlerChain(epMetaData, HandlerType.PRE, clearExistingHandlers);
+ impl.initHandlerChain(epMetaData, HandlerType.ENDPOINT,
clearExistingHandlers);
+ impl.initHandlerChain(epMetaData, HandlerType.POST, clearExistingHandlers);
- // The regular handler chain
- List<Handler> endpointChain = handlerResolver.getHandlerChain(portInfo);
- binding.setHandlerChain(endpointChain);
- }
+ List<Handler> preChain = impl.getHandlerChain(portInfo,
HandlerType.PRE);
+ List<Handler> postChain = impl.getHandlerChain(portInfo,
HandlerType.POST);
+
+ binding.setHandlerChain(postChain, HandlerType.POST);
+ binding.setHandlerChain(preChain, HandlerType.PRE);
+ }
+
+ // The regular handler chain
+ List<Handler> endpointChain = handlerResolver.getHandlerChain(portInfo);
+ binding.setHandlerChain(endpointChain);
+ }
}
/**
@@ -389,26 +388,26 @@
configProvider.setConfigName(configName, configFile);
}
- /**
- * Retrieve header names that can be processed by this binding
- * @return
- */
- public Set<QName> getHeaders()
+ /**
+ * Retrieve header names that can be processed by this binding
+ * @return
+ */
+ public Set<QName> getHeaders()
{
- Set<QName> headers = new HashSet<QName>();
+ Set<QName> headers = new HashSet<QName>();
- BindingExt binding = (BindingExt)getBinding();
+ BindingExt binding = (BindingExt)getBinding();
- for(HandlerType type : HANDLER_TYPES)
- {
- for(Handler bindingHandler : binding.getHandlerChain(type))
- {
- if(bindingHandler instanceof SOAPHandler)
- headers.addAll( ((SOAPHandler)bindingHandler).getHeaders());
- }
- }
-
- return headers;
+ for (HandlerType type : HANDLER_TYPES)
+ {
+ for (Handler bindingHandler : binding.getHandlerChain(type))
+ {
+ if (bindingHandler instanceof SOAPHandler)
+ headers.addAll(((SOAPHandler)bindingHandler).getHeaders());
+ }
+ }
+
+ return headers;
}
@Override
@@ -417,13 +416,4 @@
Object bool = getRequestContext().get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
return Boolean.TRUE.equals(bool);
}
-
- private PortInfo getPortInfo(EndpointMetaData epMetaData)
- {
- QName serviceName = epMetaData.getServiceMetaData().getServiceName();
- QName portName = epMetaData.getPortName();
- String bindingID = epMetaData.getBindingId();
- PortInfo portInfo = new PortInfoImpl(serviceName, portName, bindingID);
- return portInfo;
- }
}
\ No newline at end of file
Modified:
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-10-07
12:05:28 UTC (rev 4688)
+++
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -24,6 +24,8 @@
// $Id$
import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -45,24 +47,37 @@
import javax.xml.ws.Response;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.Service.Mode;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.soap.SOAPFaultException;
import org.jboss.logging.Logger;
import org.jboss.util.NotImplementedException;
import org.jboss.ws.WSException;
+import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.ConfigProvider;
import org.jboss.ws.core.MessageAbstraction;
import org.jboss.ws.core.client.HTTPRemotingConnection;
import org.jboss.ws.core.client.RemotingConnection;
import org.jboss.ws.core.client.SOAPRemotingConnection;
+import org.jboss.ws.core.jaxws.binding.BindingExt;
import org.jboss.ws.core.jaxws.binding.BindingProviderImpl;
+import org.jboss.ws.core.jaxws.handler.HandlerChainExecutor;
+import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
+import org.jboss.ws.core.jaxws.handler.MessageContextJAXWS;
+import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
+import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.metadata.config.ConfigurationProvider;
+import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ServiceMetaData;
import org.jboss.ws.metadata.wsse.WSSecurityConfigFactory;
import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
/**
* The Dispatch interface provides support for the dynamic invocation of a service
endpoint operations.
@@ -77,17 +92,20 @@
private final Logger log = Logger.getLogger(DispatchImpl.class);
private BindingProvider bindingProvider;
- private EndpointMetaData epMetaData;
+ private HandlerResolverImpl handlerResolver;
+ private ClientEndpointMetaData epMetaData;
private JAXBContext jaxbContext;
private ExecutorService executor;
private String securityConfig;
private Class type;
private Mode mode;
+ private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+
public DispatchImpl(ExecutorService executor, EndpointMetaData epMetaData,
Class<T> type, Mode mode)
{
this.bindingProvider = new BindingProviderImpl(epMetaData);
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.executor = executor;
this.type = type;
this.mode = mode;
@@ -97,7 +115,7 @@
public DispatchImpl(ExecutorService executor, EndpointMetaData epMetaData, JAXBContext
jbc, Mode mode)
{
this.bindingProvider = new BindingProviderImpl(epMetaData);
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.executor = executor;
this.type = Object.class;
this.jaxbContext = jbc;
@@ -119,11 +137,49 @@
return retObj;
}
- private Object invokeInternal(Object obj, Map<String, Object> resContext) throws
IOException
+ private Object invokeInternal(Object obj, Map<String, Object> resContext) throws
Exception
{
+ Object retObj = null;
+
+ BindingExt binding = (BindingExt)bindingProvider.getBinding();
+
+ String bindingID = binding.getBindingID();
+ if (bindingID.indexOf("soap") > 0)
+ {
+ // Init the handler chain
+ if (handlerResolver == null)
+ {
+ handlerResolver = new HandlerResolverImpl();
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.PRE, true);
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.ENDPOINT, true);
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.POST, true);
+
+ PortInfo portInfo = epMetaData.getPortInfo();
+ List<Handler> preChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.PRE);
+ List<Handler> epChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.ENDPOINT);
+ List<Handler> postChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.POST);
+
+ binding.setHandlerChain(preChain, HandlerType.PRE);
+ binding.setHandlerChain(epChain, HandlerType.ENDPOINT);
+ binding.setHandlerChain(postChain, HandlerType.POST);
+ }
+
+ retObj = invokeInternalSOAP(obj);
+ }
+ else
+ {
+ retObj = invokeInternalNonSOAP(obj);
+ }
+ return retObj;
+ }
+
+ private Object invokeInternalSOAP(Object obj) throws Exception
+ {
+ Object retObj = null;
+
MessageAbstraction reqMsg = getRequestMessage(obj);
String targetAddress = epMetaData.getEndpointAddress();
-
+
// R2744 A HTTP request MESSAGE MUST contain a SOAPAction HTTP header field
// with a quoted value equal to the value of the soapAction attribute of
// soapbind:operation, if present in the corresponding WSDL description.
@@ -132,22 +188,88 @@
// with a quoted empty string value, if in the corresponding WSDL description,
// the soapAction attribute of soapbind:operation is either not present, or
// present with an empty string as its value.
- String bindingID = ((Binding21)bindingProvider.getBinding()).getBindingID();
- if (bindingID.indexOf("soap") > 0)
+ String soapAction = null;
+ Map<String, Object> reqContext = getRequestContext();
+ Boolean useSOAPAction =
(Boolean)reqContext.get(BindingProvider.SOAPACTION_USE_PROPERTY);
+ if (Boolean.TRUE.equals(useSOAPAction))
{
- String soapAction = null;
- Map<String, Object> reqContext = getRequestContext();
- Boolean useSOAPAction =
(Boolean)reqContext.get(BindingProvider.SOAPACTION_USE_PROPERTY);
- if (Boolean.TRUE.equals(useSOAPAction))
+ soapAction = (String)reqContext.get(BindingProvider.SOAPACTION_URI_PROPERTY);
+ if (soapAction == null)
+ throw new IllegalStateException("Cannot obtain: " +
BindingProvider.SOAPACTION_URI_PROPERTY);
+ }
+ MimeHeaders mimeHeaders = reqMsg.getMimeHeaders();
+ mimeHeaders.addHeader("SOAPAction", soapAction != null ? soapAction :
"");
+
+ // Get the order of pre/post handlerchains
+ HandlerType[] handlerType = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+ HandlerType[] faultType = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+
+ // Associate a message context with the current thread
+ CommonMessageContext msgContext = new SOAPMessageContextJAXWS();
+ MessageContextAssociation.pushMessageContext(msgContext);
+
+ // The contents of the request context are used to initialize the message context
(see section 9.4.1)
+ // prior to invoking any handlers (see chapter 9) for the outbound message. Each
property within the
+ // request context is copied to the message context with a scope of HANDLER.
+ msgContext.put(MessageContextJAXWS.MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);
+ msgContext.putAll(reqContext);
+
+ QName portName = epMetaData.getPortName();
+ try
+ {
+ // Call the request handlers
+ boolean handlerPass = callRequestHandlerChain(portName, handlerType[0]);
+ handlerPass = handlerPass && callRequestHandlerChain(portName,
handlerType[1]);
+ handlerPass = handlerPass && callRequestHandlerChain(portName,
handlerType[2]);
+
+ // Handlers might have replaced the message
+ reqMsg = msgContext.getMessageAbstraction();
+
+ MessageAbstraction resMsg = null;
+ if (handlerPass)
{
- soapAction =
(String)reqContext.get(BindingProvider.SOAPACTION_URI_PROPERTY);
- if (soapAction == null)
- throw new IllegalStateException("Cannot obtain: " +
BindingProvider.SOAPACTION_URI_PROPERTY);
+ resMsg = getRemotingConnection().invoke(reqMsg, targetAddress, false);
+
+ // Call the response handler chain, removing the fault type entry will not
call handleFault for that chain
+ handlerPass = callResponseHandlerChain(portName, handlerType[2]);
+ faultType[2] = null;
+ handlerPass = handlerPass && callResponseHandlerChain(portName,
handlerType[1]);
+ faultType[1] = null;
+ handlerPass = handlerPass && callResponseHandlerChain(portName,
handlerType[0]);
+ faultType[0] = null;
}
- MimeHeaders mimeHeaders = reqMsg.getMimeHeaders();
- mimeHeaders.addHeader("SOAPAction", soapAction != null ? soapAction :
"");
+
+ if (handlerPass)
+ {
+ retObj = getReturnObject(resMsg);
+ }
}
-
+ catch (Exception ex)
+ {
+ if (faultType[2] != null)
+ callFaultHandlerChain(portName, faultType[2], ex);
+ if (faultType[1] != null)
+ callFaultHandlerChain(portName, faultType[1], ex);
+ if (faultType[0] != null)
+ callFaultHandlerChain(portName, faultType[0], ex);
+
+ throw ex;
+ }
+ finally
+ {
+ MessageContextAssociation.popMessageContext();
+
+ closeHandlerChain(portName, handlerType[2]);
+ closeHandlerChain(portName, handlerType[1]);
+ closeHandlerChain(portName, handlerType[0]);
+ }
+ return retObj;
+ }
+
+ private Object invokeInternalNonSOAP(Object obj) throws IOException
+ {
+ MessageAbstraction reqMsg = getRequestMessage(obj);
+ String targetAddress = epMetaData.getEndpointAddress();
MessageAbstraction resMsg = getRemotingConnection().invoke(reqMsg, targetAddress,
false);
Object retObj = getReturnObject(resMsg);
return retObj;
@@ -266,7 +388,7 @@
{
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault fault = factory.createFault("Request object cannot be
null", new QName("http://org.jboss.ws", "Dispatch"));
- fault.setFaultActor("client");
+ fault.setFaultActor("client");
throw new SOAPFaultException(fault);
}
catch (SOAPException e)
@@ -327,7 +449,7 @@
throw new IllegalArgumentException("Async response cannot be
null");
if (payload == null)
throw new IllegalArgumentException("Async payload cannot be
null");
-
+
this.response = response;
this.handler = handler;
this.payload = payload;
@@ -404,7 +526,7 @@
{
epMetaData.setConfigName(configName, configFile);
}
-
+
public String getSecurityConfig()
{
return securityConfig;
@@ -413,7 +535,7 @@
public void setSecurityConfig(String securityConfig)
{
this.securityConfig = securityConfig;
-
+
if (securityConfig != null)
{
ServiceMetaData serviceMetaData = epMetaData.getServiceMetaData();
@@ -433,4 +555,36 @@
}
}
}
+
+ private boolean callRequestHandlerChain(QName portName, HandlerType type)
+ {
+ BindingExt binding = (BindingExt)bindingProvider.getBinding();
+ HandlerChainExecutor executor = new HandlerChainExecutor(epMetaData,
binding.getHandlerChain(type));
+ executorMap.put(type, executor);
+
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ return executor.handleMessage(msgContext);
+ }
+
+ private boolean callResponseHandlerChain(QName portName, HandlerType type)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ return (executor != null ? executor.handleMessage(msgContext) : true);
+ }
+
+ private boolean callFaultHandlerChain(QName portName, HandlerType type, Exception ex)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ return (executor != null ? executor.handleFault(msgContext, ex) : true);
+ }
+
+ private void closeHandlerChain(QName portName, HandlerType type)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ if (executor != null)
+ executor.close(msgContext);
+ }
}
Modified:
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java 2007-10-07
12:05:28 UTC (rev 4688)
+++
stack/native/branches/tdiesler/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -23,10 +23,12 @@
// $Id$
+import org.jboss.ws.core.jaxws.handler.PortInfoImpl;
import org.jboss.ws.metadata.config.ConfigurationProvider;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
import javax.xml.namespace.QName;
+import javax.xml.ws.handler.PortInfo;
/**
* Client side endpoint meta data.
@@ -60,6 +62,15 @@
this.endpointAddress = endpointAddress;
}
+ public PortInfo getPortInfo()
+ {
+ QName serviceName = getServiceMetaData().getServiceName();
+ QName portName = getPortName();
+ String bindingID = getBindingId();
+ PortInfo portInfo = new PortInfoImpl(serviceName, portName, bindingID);
+ return portInfo;
+ }
+
public String toString()
{
StringBuilder buffer = new StringBuilder("\nClientEndpointMetaData:");
Added:
stack/native/branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
===================================================================
---
stack/native/branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
(rev 0)
+++
stack/native/branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java 2007-10-08
09:12:20 UTC (rev 4689)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.wssecurity;
+
+import java.io.File;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+
+import junit.framework.Test;
+
+import org.jboss.ws.core.ConfigProvider;
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * WS-Security with JAX-WS Dispatch
+ *
+ *
http://jira.jboss.org/jira/browse/JBWS-1817
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 02-Oct-2007
+ */
+public class SimpleDispatchTestCase extends JBossWSTest
+{
+ private static Dispatch dispatch;
+
+ public static Test suite() throws Exception
+ {
+ return new JBossWSTestSetup(SimpleDispatchTestCase.class,
"jaxws-samples-wssecurity-username.war");
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ if (dispatch == null)
+ {
+ URL wsdlURL = new
File("resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl").toURL();
+ URL securityURL = new
File("resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml").toURL();
+ QName serviceName = new
QName("http://org.jboss.ws/samples/wssecurity", "UsernameService");
+ QName portName = new QName("http://org.jboss.ws/samples/wssecurity",
"UsernameEndpointPort");
+
+ Service service = Service.create(wsdlURL, serviceName);
+ dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD);
+
+ ((ConfigProvider)dispatch).setSecurityConfig(securityURL.toExternalForm());
+ ((ConfigProvider)dispatch).setConfigName("Standard WSSecurity
Client");
+ }
+ }
+
+ public void testUsernameTokenNegative() throws Exception
+ {
+ try
+ {
+ String payload = "<ns1:getUsernameToken
xmlns:ns1='http://org.jboss.ws/samples/wssecurity'/>";
+ dispatch.invoke(new StreamSource(new StringReader(payload)));
+ fail("Server should respond with [401] - Unauthorized");
+ }
+ catch (Exception ex)
+ {
+ // this should be ok
+ }
+ }
+
+ public void testUsernameToken() throws Exception
+ {
+ Map<String, Object> reqContext = dispatch.getRequestContext();
+ reqContext.put(BindingProvider.USERNAME_PROPERTY, "kermit");
+ reqContext.put(BindingProvider.PASSWORD_PROPERTY, "thefrog");
+
+ String payload = "<ns1:getUsernameToken
xmlns:ns1='http://org.jboss.ws/samples/wssecurity'/>";
+ dispatch.invoke(new StreamSource(new StringReader(payload)));
+ }
+}
\ No newline at end of file