Author: jim.ma
Date: 2015-03-13 04:20:28 -0400 (Fri, 13 Mar 2015)
New Revision: 19560
Added:
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
Modified:
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly800/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly900/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml
stack/cxf/branches/management/modules/server/pom.xml
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
stack/cxf/branches/management/pom.xml
Log:
[JBWS-3881]:Create intereceptors to respond the url which query endpoint configuration and
metrics
Modified:
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly800/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml
===================================================================
---
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly800/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml 2015-03-13
08:15:43 UTC (rev 19559)
+++
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly800/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml 2015-03-13
08:20:28 UTC (rev 19560)
@@ -68,6 +68,7 @@
<module name="org.jboss.logging" />
<module name="org.apache.ws.security" />
<module name="org.picketbox" />
+ <module name="org.codehaus.jettison" />
<module name="org.springframework.spring"
optional="true">
<imports>
<include path="META-INF"/>
Modified:
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly900/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml
===================================================================
---
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly900/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml 2015-03-13
08:15:43 UTC (rev 19559)
+++
stack/cxf/branches/management/modules/resources/src/main/resources/modules/wildfly900/org/jboss/ws/cxf/jbossws-cxf-server/main/module.xml 2015-03-13
08:20:28 UTC (rev 19560)
@@ -68,6 +68,7 @@
<module name="org.jboss.logging" />
<module name="org.apache.ws.security" />
<module name="org.picketbox" />
+ <module name="org.codehaus.jettison"/>
<module name="org.springframework.spring"
optional="true">
<imports>
<include path="META-INF"/>
Modified: stack/cxf/branches/management/modules/server/pom.xml
===================================================================
--- stack/cxf/branches/management/modules/server/pom.xml 2015-03-13 08:15:43 UTC (rev
19559)
+++ stack/cxf/branches/management/modules/server/pom.xml 2015-03-13 08:20:28 UTC (rev
19560)
@@ -251,6 +251,10 @@
<artifactId>jboss-jms-api_1.1_spec</artifactId>
</dependency>
<dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
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-13
08:15:43 UTC (rev 19559)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java 2015-03-13
08:20:28 UTC (rev 19560)
@@ -71,6 +71,7 @@
import org.jboss.wsf.stack.cxf.extensions.policy.PolicySetsAnnotationListener;
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.HandlerAuthInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.NsCtxSelectorStoreInterceptor;
import org.jboss.wsf.stack.cxf.interceptor.WSDLSoapAddressRewriteInterceptor;
@@ -204,6 +205,7 @@
//with the proper spi Endpoint retrieved in CXFServletExt
bus.getInInterceptors().add(new EndpointAssociationInterceptor());
bus.getInInterceptors().add(new EnableDecoupledFaultInterceptor());
+ bus.getInInterceptors().add(new EndpointConfigsGetInterceptor());
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/EndpointConfigsGetInterceptor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java
(rev 0)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.java 2015-03-13
08:20:28 UTC (rev 19560)
@@ -0,0 +1,130 @@
+/*
+ * 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 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
+ * responds to get url like
http://localhost:8080/context/wsendpoint/management?config
+ *@author <a href="mailto:ema@redhat.com>Jim Ma</a>
+ *
+ */
+
+public class EndpointConfigsGetInterceptor extends
AbstractPhaseInterceptor<Message> {
+ public static final EndpointConfigsGetInterceptor INSTANCE = new
EndpointConfigsGetInterceptor();
+ public static final String ENDPOINT_CONFIGS =
EndpointConfigsGetInterceptor.class.getName() + ".EndpointConfigs";
+ private Interceptor<Message> configsOutInteceptor =
EndpointConfigsGetOutIntercetpor.INSTANCE;
+ private static final String TRANSFORM_SKIP = "transform.skip";
+ public EndpointConfigsGetInterceptor() {
+ super(Phase.READ);
+ getAfter().add(EndpointSelectionInterceptor.class.getName());
+ }
+
+ public EndpointConfigsGetInterceptor(Interceptor<Message> outInterceptor) {
+ this();
+ // Let people override the EndpointConfigsGetOutIntercetpor
+ configsOutInteceptor = 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);
+ HttpServletRequest request =
(HttpServletRequest)message.get("HTTP.REQUEST");
+ if (!"GET".equals(method) || StringUtils.isEmpty(query) ||
!isValidUser(request)) {
+ 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)) {
+
+ 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(
+ 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(GZIPOutInterceptor.class)
+ &&
!inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
+ outMessage.getInterceptorChain().remove(inInterceptor);
+ }
+ }
+
+ }
+ private boolean isRecognizedQuery(Map<String, String> map) {
+
+ if (map.containsKey("config")) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isValidUser(HttpServletRequest req) {
+ if (req.getUserPrincipal() != null && req.isUserInRole("admin"))
{
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
Property changes on:
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetInterceptor.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/EndpointConfigsGetOutIntercetpor.java
===================================================================
---
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java
(rev 0)
+++
stack/cxf/branches/management/modules/server/src/main/java/org/jboss/wsf/stack/cxf/interceptor/EndpointConfigsGetOutIntercetpor.java 2015-03-13
08:20:28 UTC (rev 19560)
@@ -0,0 +1,105 @@
+/*
+ * 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 java.util.Map;
+
+import org.apache.cxf.common.util.StringUtils;
+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 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 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();
+ }
+ }
+ 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/EndpointConfigsGetOutIntercetpor.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Modified: stack/cxf/branches/management/pom.xml
===================================================================
--- stack/cxf/branches/management/pom.xml 2015-03-13 08:15:43 UTC (rev 19559)
+++ stack/cxf/branches/management/pom.xml 2015-03-13 08:20:28 UTC (rev 19560)
@@ -111,6 +111,7 @@
<arquillian-wildfly-container.version>1.0.0.Alpha5</arquillian-wildfly-container.version>
<jaspi.api.version>1.0.0.Alpha1</jaspi.api.version>
<javax.inject.version>1</javax.inject.version>
+ <jettison.version>1.3.1</jettison.version>
</properties>
@@ -1273,6 +1274,17 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>${jettison.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</dependencyManagement>