Author: rsearls
Date: 2014-05-20 16:17:18 -0400 (Tue, 20 May 2014)
New Revision: 18685
Added:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
Log:
replace WSDLGetInterceptor with jbossws's WSDLSoapAddressRewriteInterceptor
Modified:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-05-20
10:24:27 UTC (rev 18684)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/EndpointImpl.java 2014-05-20
20:17:18 UTC (rev 18685)
@@ -22,7 +22,9 @@
package org.jboss.wsf.stack.cxf.deployment;
import java.io.IOException;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -30,11 +32,15 @@
import org.apache.cxf.Bus;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.frontend.WSDLGetInterceptor;
+import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
+import org.apache.cxf.message.Message;
import org.apache.cxf.service.Service;
import org.jboss.ws.common.configuration.ConfigHelper;
import org.jboss.wsf.spi.metadata.config.CommonConfig;
import org.jboss.wsf.stack.cxf.Loggers;
+import org.jboss.wsf.stack.cxf.interceptor.WSDLSoapAddressRewriteInterceptor;
/**
* An extension of @see org.apache.cxf.jaxws.EndpointImpl for dealing with
@@ -64,6 +70,23 @@
{
super.getServerFactory().setBlockPostConstruct(true);
super.doPublish(addr);
+ /**/
+ //-- rls test start
+ Collection<Endpoint> epList = super.getService().getEndpoints().values();
+ for(Endpoint ep: epList){
+ List<Interceptor<? extends Message>> inList =
ep.getInInterceptors();
+ for(Interceptor in: inList){
+ if (in instanceof org.apache.cxf.frontend.WSDLGetInterceptor){
+ int index = inList.indexOf(in);
+ if (index > -1){
+ inList.remove(index);
+ inList.add(index, WSDLSoapAddressRewriteInterceptor.INSTANCE);
+ }
+ }
+ }
+ }
+ //-- rls test end
+ /**/
//allow for configuration so that the wsdlPublisher can be set be the
JBossWSCXFConfigurer
configureObject(this);
setupConfigHandlers();
Added:
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
===================================================================
---
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java
(rev 0)
+++
stack/cxf/branches/rsearls/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/WSDLSoapAddressRewriteInterceptor.java 2014-05-20
20:17:18 UTC (rev 18685)
@@ -0,0 +1,136 @@
+package org.jboss.wsf.stack.cxf.interceptor;
+
+import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.UrlUtils;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.frontend.WSDLGetOutInterceptor;
+import org.apache.cxf.frontend.WSDLGetUtils;
+import org.jboss.ws.common.management.AbstractServerConfig;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.stack.cxf.addressRewrite.SoapAddressRewriteHelper;
+import org.jboss.wsf.stack.cxf.interceptor.util.WSDLSoapAddressRewriteUtils;
+import org.apache.cxf.interceptor.*;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
+import org.w3c.dom.Document;
+
+import java.security.AccessController;
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * This is a customization of org.apache.cxf.frontend.WSDLGetInterceptor. It
+ * enables the handling of rewriting the path of a URL.
+ * Date: 5/19/14
+ */
+public class WSDLSoapAddressRewriteInterceptor extends
AbstractPhaseInterceptor<Message> {
+ public static final WSDLSoapAddressRewriteInterceptor INSTANCE =
+ new WSDLSoapAddressRewriteInterceptor();
+ public static final String DOCUMENT_HOLDER =
+ WSDLSoapAddressRewriteInterceptor.class.getName() + ".documentHolder";
+ private static final String TRANSFORM_SKIP = "transform.skip";
+ private Interceptor<Message> wsdlGetOutInterceptor =
WSDLGetOutInterceptor.INSTANCE;
+
+ public WSDLSoapAddressRewriteInterceptor() {
+ super(Phase.READ);
+ getAfter().add(EndpointSelectionInterceptor.class.getName());
+ }
+
+ public WSDLSoapAddressRewriteInterceptor(Interceptor<Message> outInterceptor) {
+ this();
+ // Let people override the wsdlGetOutInterceptor
+ wsdlGetOutInterceptor = outInterceptor;
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
+ String query = (String)message.get(Message.QUERY_STRING);
+
+ if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
+ return;
+ }
+
+ String baseUri = (String)message.get(Message.REQUEST_URL);
+ String ctx = (String)message.get(Message.PATH_INFO);
+
+ Map<String, String> map = UrlUtils.parseQueryString(query);
+ if (isRecognizedQuery(map, baseUri, ctx,
message.getExchange().getEndpoint().getEndpointInfo())) {
+ Document doc = getDocument(message, baseUri, map, ctx);
+
+ Endpoint e = message.getExchange().get(Endpoint.class);
+ Message mout = new MessageImpl();
+ mout.setExchange(message.getExchange());
+ mout = e.getBinding().createMessage(mout);
+
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
+ message.getExchange().setOutMessage(mout);
+
+ mout.put(DOCUMENT_HOLDER, doc);
+ mout.put(Message.CONTENT_TYPE, "text/xml");
+
+ // just remove the interceptor which should not be used
+ cleanUpOutInterceptors(mout);
+
+ // notice this is being added after the purge above, don't swap the order!
+ mout.getInterceptorChain().add(wsdlGetOutInterceptor);
+
+ message.getExchange().put(TRANSFORM_SKIP, Boolean.TRUE);
+ // skip the service executor and goto the end of the chain.
+ message.getInterceptorChain().doInterceptStartingAt(
+ message,
+ OutgoingChainInterceptor.class.getName());
+ }
+ }
+
+ protected void cleanUpOutInterceptors(Message outMessage) {
+ // TODO - how can I improve this to provide a specific interceptor chain that just
has the
+ // stax, gzip and message sender components, while also ensuring that GZIP is only
provided
+ // if its already configured for the endpoint.
+ Iterator<Interceptor<? extends Message>> iterator =
outMessage.getInterceptorChain().iterator();
+ while (iterator.hasNext()) {
+ Interceptor<? extends Message> inInterceptor = iterator.next();
+ if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
+ && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
+ && !inInterceptor.getClass().equals(MessageSenderInterceptor.class))
{
+ outMessage.getInterceptorChain().remove(inInterceptor);
+ }
+ }
+
+ }
+
+ private Document getDocument(Message message, String base, Map<String, String>
params, String ctxUri) {
+ // cannot have two wsdl's being generated for the same endpoint at the same
+ // time as the addresses may get mixed up
+ // For WSDL's the WSDLWriter does not share any state between documents.
+ // For XSD's, the WSDLSoapAddressRewriteUtils makes a copy of any XSD schema
documents before updating
+ // any addresses and returning them, so for both WSDL and XSD this is the only part
that needs
+ // to be synchronized.
+ synchronized (message.getExchange().getEndpoint()) {
+ return new WSDLGetUtils().getDocument(message, base, params, ctxUri,
+ message.getExchange().getEndpoint().getEndpointInfo());
+ }
+ }
+
+ private boolean isRecognizedQuery(Map<String, String> map, String baseUri,
String ctx,
+ EndpointInfo endpointInfo) {
+
+ if (map.containsKey("wsdl") || map.containsKey("xsd")) {
+ return true;
+ }
+ return false;
+ }
+
+
+ private static ServerConfig getServerConfig() {
+ if(System.getSecurityManager() == null) {
+ return AbstractServerConfig.getServerIntegrationServerConfig();
+ }
+ return
AccessController.doPrivileged(AbstractServerConfig.GET_SERVER_INTEGRATION_SERVER_CONFIG);
+ }
+
+}
Show replies by date