Author: jim.ma
Date: 2015-03-16 05:53:57 -0400 (Mon, 16 Mar 2015)
New Revision: 19569
Added:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/AbstractEndpintManagementInterceptor.java
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutInterceptor.java
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutOutIntercetpor.java
Modified:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java
stack/cxf/branches/management/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/samples/context/WebServiceContextJSETestCase.java
Log:
[JBWS-3881]:Add interceptor to allow configure runtime configurations on Endpoint
Modified:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java 2015-03-16
09:28:45 UTC (rev 19568)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -22,8 +22,6 @@
package org.jboss.wsf.stack.cxf;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
@@ -50,7 +48,7 @@
import org.jboss.ws.common.management.AbstractServerConfig;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.invocation.InvocationContext;
+import org.jboss.wsf.spi.deployment.RuntimeConfig;
import org.jboss.wsf.spi.invocation.RequestHandler;
import org.jboss.wsf.spi.management.EndpointMetrics;
import org.jboss.wsf.spi.management.ServerConfig;
@@ -94,7 +92,7 @@
out.close();
return;
}
- final boolean statisticsEnabled = getServerConfig().isStatisticsEnabled();
+ final boolean statisticsEnabled = getServerConfig().isStatisticsEnabled() ||
"true".equals(ep.getRuntimeProperty(RuntimeConfig.STATISTICS_ENABLED));
final Long beginTime = statisticsEnabled == true ? initRequestMetrics(ep) : 0;
final Deployment dep = ep.getService().getDeployment();
final AbstractHTTPDestination dest = findDestination(req,
dep.getAttachment(BusHolder.class).getBus());
Modified:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2015-03-16
09:28:45 UTC (rev 19568)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -72,6 +72,7 @@
import org.jboss.wsf.stack.cxf.interceptor.EnableDecoupledFaultInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.EndpointAssociationInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.EndpointConfigsGetInterceptor;
+import org.jboss.wsf.stack.cxf.interceptor.EndpointConfigsPutInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.HandlerAuthInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.NsCtxSelectorStoreInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.WSDLSoapAddressRewriteInterceptor;
@@ -206,6 +207,7 @@
bus.getInInterceptors().add(new EndpointAssociationInterceptor());
bus.getInInterceptors().add(new EnableDecoupledFaultInterceptor());
bus.getInInterceptors().add(new EndpointConfigsGetInterceptor());
+ bus.getInInterceptors().add(new EndpointConfigsPutInterceptor());
bus.getInInterceptors().add(new NsCtxSelectorStoreInterceptor());
final String p = (props != null) ?
props.get(Constants.JBWS_CXF_DISABLE_HANDLER_AUTH_CHECKS) : null;
Added:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/AbstractEndpintManagementInterceptor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/AbstractEndpintManagementInterceptor.java
(rev 0)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/AbstractEndpintManagementInterceptor.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2015, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.wsf.stack.cxf.interceptor;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.common.util.UrlUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.MessageSenderInterceptor;
+import org.apache.cxf.interceptor.OutgoingChainInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
+
+/**
+ * All endpoint management interceptor should extend this class to get allowed http
methods etc.
+ * @author <a href="mailto:ema@redhat.com/>Jim Ma</a>
+ *
+ */
+public abstract class AbstractEndpintManagementInterceptor extends
AbstractPhaseInterceptor<Message>
+{
+ private static final String TRANSFORM_SKIP = "transform.skip";
+
+ public AbstractEndpintManagementInterceptor(String phase)
+ {
+ super(phase);
+ }
+
+ abstract Set<String> getAllowedMethod();
+
+ protected boolean isAllowed(final Message message) throws Fault
+ {
+ String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
+ if (getAllowedMethod().contains(method) &&
isValidUser(getHttpRequest(message)))
+ {
+ return true;
+ }
+ return false;
+
+ }
+
+ private boolean isValidUser(final HttpServletRequest req)
+ {
+ if (req.getUserPrincipal() != null && req.isUserInRole("admin"))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ protected HttpServletRequest getHttpRequest(Message message)
+ {
+ return (HttpServletRequest)message.get("HTTP.REQUEST");
+ }
+
+ protected Map<String, String> getQueryMap(Message message)
+ {
+ String query = (String)message.get(Message.QUERY_STRING);
+ Map<String, String> map = UrlUtils.parseQueryString(query);
+ return map;
+ }
+
+ 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(GZIPOutInterceptor.class) &&
!inInterceptor.getClass().equals(MessageSenderInterceptor.class))
+ {
+ outMessage.getInterceptorChain().remove(inInterceptor);
+ }
+ }
+ outMessage.getExchange().put(TRANSFORM_SKIP, Boolean.TRUE);
+
+ }
+
+ protected Message createOutMessage(Message message)
+ {
+ Message mout = new MessageImpl();
+ mout.setExchange(message.getExchange());
+ mout =
message.getExchange().get(org.apache.cxf.endpoint.Endpoint.class).getBinding().createMessage(mout);
+
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
+ message.getExchange().setOutMessage(mout);
+ return mout;
+ }
+}
Property changes on:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/AbstractEndpintManagementInterceptor.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Modified:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java 2015-03-16
09:28:45 UTC (rev 19568)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -21,23 +21,16 @@
*/
package org.jboss.wsf.stack.cxf.interceptor;
-import java.util.Iterator;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
-import javax.servlet.http.HttpServletRequest;
-
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.interceptor.Fault;
import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.MessageSenderInterceptor;
import org.apache.cxf.interceptor.OutgoingChainInterceptor;
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.transport.common.gzip.GZIPOutInterceptor;
import org.jboss.wsf.spi.deployment.Endpoint;
/**
* Interceptor to get json format endpoint config info. This interceptor is only
@@ -46,11 +39,16 @@
*
*/
-public class EndpointConfigsGetInterceptor extends
AbstractPhaseInterceptor<Message> {
+public class EndpointConfigsGetInterceptor extends AbstractEndpintManagementInterceptor
{
public static final EndpointConfigsGetInterceptor INSTANCE = new
EndpointConfigsGetInterceptor();
public static final String ENDPOINT_CONFIGS =
EndpointConfigsGetInterceptor.class.getName() + ".EndpointConfigs";
+ public static final Set<String> httpMethods = new HashSet<String>(4);
private Interceptor<Message> configsOutInteceptor =
EndpointConfigsGetOutIntercetpor.INSTANCE;
private static final String TRANSFORM_SKIP = "transform.skip";
+ static {
+ httpMethods.add("GET");
+ httpMethods.add("POST");
+ }
public EndpointConfigsGetInterceptor() {
super(Phase.READ);
getAfter().add(EndpointSelectionInterceptor.class.getName());
@@ -63,34 +61,19 @@
}
public void handleMessage(Message message) throws Fault {
- String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
- String query = (String)message.get(Message.QUERY_STRING);
- HttpServletRequest request =
(HttpServletRequest)message.get("HTTP.REQUEST");
- if (!"GET".equals(method) || StringUtils.isEmpty(query) ||
!isValidUser(request)) {
- return;
+ if (!isAllowed(message)) {
+ 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)) {
-
+ if (isRecognizedQuery(getQueryMap(message))) {
+ Message mout = this.createOutMessage(message);
Endpoint endpoint = message.getExchange().get(Endpoint.class);
-
- Message mout = new MessageImpl();
- mout.setExchange(message.getExchange());
- mout =
message.getExchange().get(org.apache.cxf.endpoint.Endpoint.class).getBinding().createMessage(mout);
-
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
- message.getExchange().setOutMessage(mout);
-
mout.put(ENDPOINT_CONFIGS, endpoint.getAllConfigsMap());
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(configsOutInteceptor);
-
message.getExchange().put(TRANSFORM_SKIP, Boolean.TRUE);
// skip the service executor and goto the end of the chain.
message.getInterceptorChain().doInterceptStartingAt(
@@ -99,32 +82,19 @@
}
}
- 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(GZIPOutInterceptor.class)
- &&
!inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
- outMessage.getInterceptorChain().remove(inInterceptor);
- }
- }
-
- }
- private boolean isRecognizedQuery(Map<String, String> map) {
- if (map.containsKey("config")) {
+ private boolean isRecognizedQuery(Map<String, String> map) {
+ if (map.containsKey("config") && map.size() == 1) {
return true;
}
return false;
}
+
+ @Override
+ Set<String> getAllowedMethod()
+ {
+ return httpMethods;
+ }
- private boolean isValidUser(HttpServletRequest req) {
- if (req.getUserPrincipal() != null && req.isUserInRole("admin"))
{
- return true;
- }
- return false;
- }
+
}
\ No newline at end of file
Modified:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java 2015-03-16
09:28:45 UTC (rev 19568)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -36,70 +36,88 @@
import org.codehaus.jettison.AbstractXMLStreamWriter;
import org.codehaus.jettison.mapped.MappedNamespaceConvention;
import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
+
/**
* Out Interceptor to get json format endpoint config info. This interceptor is only
* responds to get url like
http://localhost:8080/context/wsendpoint/management?config
*@author <a href="mailto:ema@redhat.com>Jim Ma</a>
*
*/
-public class EndpointConfigsGetOutIntercetpor extends
AbstractPhaseInterceptor<Message> {
- public static final EndpointConfigsGetOutIntercetpor INSTANCE = new
EndpointConfigsGetOutIntercetpor();
+public class EndpointConfigsGetOutIntercetpor extends
AbstractPhaseInterceptor<Message>
+{
+ public static final EndpointConfigsGetOutIntercetpor INSTANCE = new
EndpointConfigsGetOutIntercetpor();
- public EndpointConfigsGetOutIntercetpor() {
- super(Phase.PRE_STREAM);
- getAfter().add(StaxOutInterceptor.class.getName());
- }
+ public EndpointConfigsGetOutIntercetpor()
+ {
+ super(Phase.PRE_STREAM);
+ getAfter().add(StaxOutInterceptor.class.getName());
+ }
- public void handleMessage(Message message) throws Fault {
- @SuppressWarnings("unchecked")
- Map<String, String> configMaps = (Map<String,
String>)message.get(EndpointConfigsGetInterceptor.ENDPOINT_CONFIGS);
- if (configMaps == null) {
- return;
- }
- message.remove(EndpointConfigsGetInterceptor.ENDPOINT_CONFIGS);
- OutputStream out = message.getContent(OutputStream.class);
- if (out == null) {
- return;
- }
- message.put(Message.CONTENT_TYPE, "text/xml");
- OutputStreamWriter writer = null;
- AbstractXMLStreamWriter mappedWriter = null;
- try {
- writer= new OutputStreamWriter(out, getEncoding(message));
- mappedWriter = new MappedXMLStreamWriter(new MappedNamespaceConvention(),
writer);
- mappedWriter.writeStartDocument();
- for (String key : configMaps.keySet()) {
- String value = configMaps.get(key);
- if (StringUtils.isEmpty(value)) {
- mappedWriter.writeEmptyElement(key);
- } else {
- mappedWriter.writeStartElement(key);
- mappedWriter.writeCharacters(configMaps.get(key));
- mappedWriter.writeEndElement();
- }
+ public void handleMessage(Message message) throws Fault
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, String> configMaps = (Map<String,
String>)message.get(EndpointConfigsGetInterceptor.ENDPOINT_CONFIGS);
+ if (configMaps == null)
+ {
+ return;
+ }
+ message.remove(EndpointConfigsGetInterceptor.ENDPOINT_CONFIGS);
+ OutputStream out = message.getContent(OutputStream.class);
+ if (out == null)
+ {
+ return;
+ }
+ message.put(Message.CONTENT_TYPE, "text/xml");
+ OutputStreamWriter writer = null;
+ AbstractXMLStreamWriter mappedWriter = null;
+ try
+ {
+ writer = new OutputStreamWriter(out, getEncoding(message));
+ mappedWriter = new MappedXMLStreamWriter(new MappedNamespaceConvention(),
writer);
+ mappedWriter.writeStartDocument();
+ for (String key : configMaps.keySet())
+ {
+ String value = configMaps.get(key);
+ if (StringUtils.isEmpty(value))
+ {
+ mappedWriter.writeEmptyElement(key);
}
- mappedWriter.writeEndDocument();
- out.flush();
- } catch (Exception e) {
- throw new Fault(e);
- } finally {
- StaxUtils.close(mappedWriter);
- }
-
- }
- private String getEncoding(Message message) {
- Exchange ex = message.getExchange();
- String encoding = (String)message.get(Message.ENCODING);
- if (encoding == null && ex.getInMessage() != null) {
- encoding = (String) ex.getInMessage().get(Message.ENCODING);
- message.put(Message.ENCODING, encoding);
- }
-
- if (encoding == null) {
- encoding = "UTF-8";
- message.put(Message.ENCODING, encoding);
- }
- return encoding;
- }
+ else
+ {
+ mappedWriter.writeStartElement(key);
+ mappedWriter.writeCharacters(configMaps.get(key));
+ mappedWriter.writeEndElement();
+ }
+ }
+ mappedWriter.writeEndDocument();
+ out.flush();
+ }
+ catch (Exception e)
+ {
+ throw new Fault(e);
+ }
+ finally
+ {
+ StaxUtils.close(mappedWriter);
+ }
+
+ }
+
+ private String getEncoding(Message message)
+ {
+ Exchange ex = message.getExchange();
+ String encoding = (String)message.get(Message.ENCODING);
+ if (encoding == null && ex.getInMessage() != null)
+ {
+ encoding = (String)ex.getInMessage().get(Message.ENCODING);
+ message.put(Message.ENCODING, encoding);
+ }
+
+ if (encoding == null)
+ {
+ encoding = "UTF-8";
+ message.put(Message.ENCODING, encoding);
+ }
+ return encoding;
+ }
}
-
Added:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutInterceptor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutInterceptor.java
(rev 0)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutInterceptor.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2015, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.wsf.stack.cxf.interceptor;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.OutgoingChainInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.jboss.wsf.spi.deployment.Endpoint;
+
+/**
+ * Interceptor to set runtime configuration with http put url like:
http://localhost:8080/context/endpoint?statistics-enabled=true
+ *@author <a href="mailto:ema@redhat.com>Jim Ma</a>
+ *
+ */
+public class EndpointConfigsPutInterceptor extends AbstractEndpintManagementInterceptor
+{
+ public static final EndpointConfigsPutInterceptor INSTANCE = new
EndpointConfigsPutInterceptor();
+ public static final String CONFIG_RESULT =
EndpointConfigsPutInterceptor.class.getName() + ".EndpointConfigPutResult";
+ public static final Set<String> httpMethods;
+ private Interceptor<Message> configPutOutInteceptor =
EndpointConfigsPutOutIntercetpor.INSTANCE;
+
+ static
+ {
+ httpMethods = new HashSet<String>(4);
+ httpMethods.add("PUT");
+ httpMethods.add("GET");
+ }
+
+ public EndpointConfigsPutInterceptor()
+ {
+ super(Phase.READ);
+ getAfter().add(EndpointSelectionInterceptor.class.getName());
+ }
+
+ public EndpointConfigsPutInterceptor(Interceptor<Message> outInterceptor)
+ {
+ this();
+ configPutOutInteceptor = outInterceptor;
+ }
+
+ @Override
+ public void handleMessage(Message message) throws Fault
+ {
+ if (!isAllowed(message))
+ {
+ return;
+ }
+ Map<String, String> queryMaps = getQueryMap(message);
+ Endpoint endpoint = message.getExchange().get(Endpoint.class);
+ for (String key : queryMaps.keySet())
+ {
+ if (!endpoint.getRuntimeConfigFlags().contains(key))
+ {
+ return;
+ }
+ }
+ Message mout = this.createOutMessage(message);
+ for (String key : queryMaps.keySet())
+ {
+ endpoint.setRuntimeProperty(key, queryMaps.get(key));
+ }
+ mout.put(CONFIG_RESULT, "Successfully set endpoint runtime
configurations.");
+ cleanUpOutInterceptors(mout);
+ mout.getInterceptorChain().add(configPutOutInteceptor);
+ message.getInterceptorChain().doInterceptStartingAt(message,
OutgoingChainInterceptor.class.getName());
+ }
+
+ @Override
+ Set<String> getAllowedMethod()
+ {
+ return httpMethods;
+ }
+}
Property changes on:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutInterceptor.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutOutIntercetpor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutOutIntercetpor.java
(rev 0)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutOutIntercetpor.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2015, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.wsf.stack.cxf.interceptor;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.codehaus.jettison.AbstractXMLStreamWriter;
+import org.codehaus.jettison.mapped.MappedNamespaceConvention;
+import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
+
+/**
+ * Out Interceptor to write json format endpoint config set result. This interceptor is
added to interceptorchain by
+ * @see org.jboss.wsf.stack.cxf.interceptor.EndpointsConfigsPutInterceptor
+ * @author <a href="mailto:ema@redhat.com">Jim Ma</a>
+ *
+ */
+public class EndpointConfigsPutOutIntercetpor extends
AbstractPhaseInterceptor<Message>
+{
+ public static final EndpointConfigsPutOutIntercetpor INSTANCE = new
EndpointConfigsPutOutIntercetpor();
+
+ public EndpointConfigsPutOutIntercetpor()
+ {
+ super(Phase.PRE_STREAM);
+ getAfter().add(StaxOutInterceptor.class.getName());
+ }
+
+ public void handleMessage(Message message) throws Fault
+ {
+ String configResult =
(String)message.get(EndpointConfigsPutInterceptor.CONFIG_RESULT);
+ if (configResult == null)
+ {
+ return;
+ }
+ message.remove(EndpointConfigsPutInterceptor.CONFIG_RESULT);
+ OutputStream out = message.getContent(OutputStream.class);
+ if (out == null)
+ {
+ return;
+ }
+ message.put(Message.CONTENT_TYPE, "text/xml");
+ OutputStreamWriter writer = null;
+ AbstractXMLStreamWriter mappedWriter = null;
+ try
+ {
+ writer = new OutputStreamWriter(out, getEncoding(message));
+ mappedWriter = new MappedXMLStreamWriter(new MappedNamespaceConvention(),
writer);
+ mappedWriter.writeStartDocument();
+
+ mappedWriter.writeStartElement("result");
+ mappedWriter.writeCharacters(configResult);
+ mappedWriter.writeEndElement();
+
+ mappedWriter.writeEndDocument();
+ out.flush();
+ }
+ catch (Exception e)
+ {
+ throw new Fault(e);
+ }
+ finally
+ {
+ StaxUtils.close(mappedWriter);
+ }
+
+ }
+
+ private String getEncoding(Message message)
+ {
+ Exchange ex = message.getExchange();
+ String encoding = (String)message.get(Message.ENCODING);
+ if (encoding == null && ex.getInMessage() != null)
+ {
+ encoding = (String)ex.getInMessage().get(Message.ENCODING);
+ message.put(Message.ENCODING, encoding);
+ }
+
+ if (encoding == null)
+ {
+ encoding = "UTF-8";
+ message.put(Message.ENCODING, encoding);
+ }
+ return encoding;
+ }
+}
Property changes on:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsPutOutIntercetpor.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Modified:
stack/cxf/branches/management/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/samples/context/WebServiceContextJSETestCase.java
===================================================================
---
stack/cxf/branches/management/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/samples/context/WebServiceContextJSETestCase.java 2015-03-16
09:28:45 UTC (rev 19568)
+++
stack/cxf/branches/management/modules/testsuite/shared-tests/src/test/java/org/jboss/test/ws/jaxws/samples/context/WebServiceContextJSETestCase.java 2015-03-16
09:53:57 UTC (rev 19569)
@@ -70,6 +70,7 @@
.addAsManifestResource(new File(JBossWSTestHelper.getTestResourcesDir() +
"/jaxws/samples/context/META-INF/permissions.xml"),
"permissions.xml")
.addAsWebInfResource(new File(JBossWSTestHelper.getTestResourcesDir() +
"/jaxws/samples/context/WEB-INF/jboss-web.xml"), "jboss-web.xml")
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() +
"/jaxws/samples/context/WEB-INF/web.xml"));
+ JBossWSTestHelper.writeToFile(archive);
return archive;
}
@@ -125,16 +126,26 @@
@Test
@RunAsClient
- public void testManagementURL() throws Exception {
- URL url = new URL(baseURL +
"/jaxws-samples-context-jse/management?config");
- String encoding = Base64.encodeBytes("jbossws:jbossws".getBytes());
- HttpURLConnection connenction = (HttpURLConnection)url.openConnection();
- connenction.setRequestProperty("Authorization", "Basic " +
encoding);
- connenction.connect();
- assertEquals(200, connenction.getResponseCode());
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- IOUtils.copy(connenction.getInputStream(), bout);
- assertTrue("Unexpected response",
bout.toString().contains("\"type\":\"JAXWS_JSE\",\"securityDomain\":\"JBossWS\""));
-
+ public void testManagementURL() throws Exception
+ {
+ URL url = new URL(baseURL +
"/jaxws-samples-context-jse/management?config");
+ String encoding = Base64.encodeBytes("jbossws:jbossws".getBytes());
+ HttpURLConnection connenction = (HttpURLConnection)url.openConnection();
+ connenction.setRequestProperty("Authorization", "Basic " +
encoding);
+ connenction.connect();
+ assertEquals(200, connenction.getResponseCode());
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ IOUtils.copy(connenction.getInputStream(), bout);
+ assertTrue("Unexpected response",
bout.toString().contains("\"type\":\"JAXWS_JSE\",\"securityDomain\":\"JBossWS\""));
+
+ url = new URL(baseURL +
"/jaxws-samples-context-jse/management?statistics-enabled=true");
+ connenction = (HttpURLConnection)url.openConnection();
+ connenction.setRequestProperty("Authorization", "Basic " +
encoding);
+ connenction.connect();
+ assertEquals(200, connenction.getResponseCode());
+ bout = new ByteArrayOutputStream();
+ IOUtils.copy(connenction.getInputStream(), bout);
+ assertTrue("Unexpected response",
bout.toString().contains("Successfully set endpoint runtime configurations"));
+
}
}