You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jp...@apache.org on 2013/07/26 10:53:51 UTC
svn commit: r1507220 - in /cxf/branches/2.7.x-fixes:
rt/frontend/simple/src/main/java/org/apache/cxf/frontend/
systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/
Author: jpell
Date: Fri Jul 26 08:53:51 2013
New Revision: 1507220
URL: http://svn.apache.org/r1507220
Log:
CXF-5151 added support for gzip ?wsdl
Added:
cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java
Modified:
cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/Server.java
Modified: cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java?rev=1507220&r1=1507219&r2=1507220&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Fri Jul 26 08:53:51 2013
@@ -19,73 +19,35 @@
package org.apache.cxf.frontend;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.util.Iterator;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import org.w3c.dom.Document;
-
import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
-import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.common.util.UrlUtils;
-import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.MessageSenderInterceptor;
+import org.apache.cxf.interceptor.OutgoingChainInterceptor;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
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.staxutils.StaxUtils;
-import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
-/**
- *
- */
public class WSDLGetInterceptor extends AbstractPhaseInterceptor<Message> {
public static final WSDLGetInterceptor INSTANCE = new WSDLGetInterceptor();
-
- private static final Logger LOG = LogUtils.getL7dLogger(WSDLGetInterceptor.class);
-
+ public static final String DOCUMENT_HOLDER = WSDLGetInterceptor.class.getName() + ".documentHolder";
+
public WSDLGetInterceptor() {
super(Phase.READ);
getAfter().add(EndpointSelectionInterceptor.class.getName());
}
-
- public void doOutput(Message message, String base, Document doc, OutputStream out)
- throws WSDLQueryException {
- String enc = null;
- try {
- enc = doc.getXmlEncoding();
- } catch (Exception ex) {
- //ignore - not dom level 3
- }
- if (enc == null) {
- enc = "utf-8";
- }
-
- XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out,
- enc);
- try {
- StaxUtils.writeNode(doc, writer, true);
- writer.flush();
- } catch (XMLStreamException e) {
- throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL",
- LOG,
- base), e);
- } finally {
- StaxUtils.close(writer);
- }
- }
-
public void handleMessage(Message message) throws Fault {
String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
@@ -93,106 +55,61 @@ public class WSDLGetInterceptor extends
if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
return;
}
+
String baseUri = (String)message.get(Message.REQUEST_URL);
String ctx = (String)message.get(Message.PATH_INFO);
-
- boolean setOutMessageToNull = false;
- try {
- CachedOutputStream cos = null;
-
- //cannot have two wsdl's being written for the same endpoint at the same
- //time as the addresses may get mixed up
- synchronized (message.getExchange().getEndpoint()) {
- Map<String, String> map = UrlUtils.parseQueryString(query);
- if (isRecognizedQuery(map, baseUri, ctx,
- message.getExchange().getEndpoint().getEndpointInfo())) {
-
- setOutMessageToNull = true;
- try {
- Document doc = getDocument(message,
- baseUri,
- map,
- ctx,
- message.getExchange().getEndpoint().getEndpointInfo());
- String enc = null;
- try {
- enc = doc.getXmlEncoding();
- } catch (Exception ex) {
- //ignore - not dom level 3
- }
- if (enc == null) {
- enc = "utf-8";
- }
-
- cos = new CachedOutputStream();
- XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(cos,
- enc);
- StaxUtils.writeNode(doc, writer, true);
- writer.flush();
- writer.close();
- } catch (XMLStreamException e) {
- throw new Fault(e);
+ // cannot have two wsdl's being written for the same endpoint at the same
+ // time as the addresses may get mixed up
+ synchronized (message.getExchange().getEndpoint()) {
+ Map<String, String> map = UrlUtils.parseQueryString(query);
+ if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
+ Document doc = getDocument(message, baseUri, map, ctx,
+ message.getExchange().getEndpoint().getEndpointInfo());
+
+ 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);
+
+ // FIXME - how can I change this to provide a different interceptor chain that just has the
+ // stax, gzip and message sender components.
+ Iterator<Interceptor<? extends Message>> iterator = mout.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)) {
+ mout.getInterceptorChain().remove(inInterceptor);
}
}
- }
-
- if (cos != null) {
- try {
- Conduit c = message.getExchange().getDestination().getBackChannel(message, null, null);
- Message mout = new MessageImpl();
- mout.setExchange(message.getExchange());
- message.getExchange().setOutMessage(mout);
- mout.put(Message.CONTENT_TYPE, "text/xml");
- c.prepare(mout);
- OutputStream os = mout.getContent(OutputStream.class);
-
- InputStream cis = cos.getInputStream();
- IOUtils.copyAndCloseInput(cis, os);
- message.getInterceptorChain().abort();
-
- try {
- os.flush();
- os.close();
- } catch (IOException ex) {
- LOG.log(Level.FINE, "Failure writing full wsdl to the stream", ex);
- //we can ignore this. Likely, whatever has requested the WSDL
- //has closed the connection before reading the entire wsdl.
- //WSDL4J has a tendency to not read the closing tags and such
- //and thus can sometimes hit this. In any case, it's
- //pretty much ignorable and nothing we can do about it (cannot
- //send a fault or anything anyway
- }
- cos.close();
- } catch (IOException e) {
- throw new Fault(e);
- }
- }
+ mout.getInterceptorChain().add(WSDLGetOutInterceptor.INSTANCE);
- } finally {
- if (setOutMessageToNull) {
- message.getExchange().setOutMessage(null);
+ // skip the service executor and goto the end of the chain.
+ message.getInterceptorChain().doInterceptStartingAt(
+ message,
+ OutgoingChainInterceptor.class.getName());
}
}
}
- public Document getDocument(Message message,
- String base,
- Map<String, String> params,
- String ctxUri,
+
+ private Document getDocument(Message message, String base, Map<String, String> params, String ctxUri,
EndpointInfo endpointInfo) {
return new WSDLGetUtils().getDocument(message, base, params, ctxUri, endpointInfo);
}
- public boolean isRecognizedQuery(Map<String, String> map,
- String baseUri,
- String ctx,
+
+ private boolean isRecognizedQuery(Map<String, String> map, String baseUri, String ctx,
EndpointInfo endpointInfo) {
- if (map.containsKey("wsdl")
- || map.containsKey("xsd")) {
+
+ if (map.containsKey("wsdl") || map.containsKey("xsd")) {
return true;
}
return false;
}
-
}
-
Added: cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java?rev=1507220&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java (added)
+++ cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java Fri Jul 26 08:53:51 2013
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.frontend;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class WSDLGetOutInterceptor extends AbstractPhaseInterceptor<Message> {
+ public static final WSDLGetOutInterceptor INSTANCE = new WSDLGetOutInterceptor();
+
+ public WSDLGetOutInterceptor() {
+ super(Phase.PRE_STREAM);
+ getAfter().add(StaxOutInterceptor.class.getName());
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ Document doc = (Document)message.get(WSDLGetInterceptor.DOCUMENT_HOLDER);
+ if (doc == null) {
+ return;
+ }
+
+ XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
+ if (writer == null) {
+ return;
+ }
+
+ try {
+ StaxUtils.writeNode(doc, writer, true);
+ } catch (XMLStreamException e) {
+ throw new Fault(e);
+ }
+
+ message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);
+ }
+}
Modified: cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?rev=1507220&r1=1507219&r2=1507220&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java Fri Jul 26 08:53:51 2013
@@ -38,6 +38,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
+import java.util.zip.GZIPInputStream;
import javax.xml.namespace.QName;
import javax.xml.ws.AsyncHandler;
@@ -75,6 +76,7 @@ import org.apache.hello_world_soap_http.
import org.apache.hello_world_soap_http.types.BareDocumentResponse;
import org.apache.hello_world_soap_http.types.GreetMeLaterResponse;
import org.apache.hello_world_soap_http.types.GreetMeResponse;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -110,6 +112,7 @@ public class ClientServerTest extends Ab
assertTrue("server did not launch correctly", launchServer(Server.class, true));
createStaticBus(url.toString());
}
+
@Test
public void testCXF2419() throws Exception {
org.apache.cxf.hello_world.elrefs.SOAPService serv
@@ -822,12 +825,15 @@ public class ClientServerTest extends Ab
@Test
public void testGetWSDL() throws Exception {
String url = "http://localhost:" + PORT + "/SoapContext/SoapPort?wsdl";
- HttpURLConnection httpConnection = getHttpConnection(url);
+ HttpURLConnection httpConnection = getHttpConnection(url);
+
+ // just testing that GZIP is not enabled by default
+ httpConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
httpConnection.connect();
assertEquals(200, httpConnection.getResponseCode());
- assertEquals("text/xml", httpConnection.getContentType());
+ assertEquals("text/xml;charset=utf-8", httpConnection.getContentType().toLowerCase());
assertEquals("OK", httpConnection.getResponseMessage());
InputStream in = httpConnection.getInputStream();
@@ -835,8 +841,23 @@ public class ClientServerTest extends Ab
Document doc = XMLUtils.parse(in);
assertNotNull(doc);
-
-
+ }
+
+ @Test
+ public void testGetWSDLWithGzip() throws Exception {
+ String url = "http://localhost:" + PORT + "/SoapContext/SoapPortWithGzip?wsdl";
+ HttpURLConnection httpConnection = getHttpConnection(url);
+ httpConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
+ httpConnection.connect();
+ assertEquals(200, httpConnection.getResponseCode());
+ assertEquals("text/xml;charset=utf-8", httpConnection.getContentType().toLowerCase());
+ assertEquals("OK", httpConnection.getResponseMessage());
+ assertEquals("gzip", httpConnection.getContentEncoding());
+ InputStream in = httpConnection.getInputStream();
+ assertNotNull(in);
+ GZIPInputStream inputStream = new GZIPInputStream(in);
+ Document doc = XMLUtils.parse(inputStream);
+ assertNotNull(doc);
}
@Test
Modified: cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/Server.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/Server.java?rev=1507220&r1=1507219&r2=1507220&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/Server.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/Server.java Fri Jul 26 08:53:51 2013
@@ -33,6 +33,8 @@ import org.apache.cxf.interceptor.URIMap
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.ServerAsyncResponse;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transport.common.gzip.GZIPInInterceptor;
+import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
import org.apache.hello_world_soap_http.BaseGreeterImpl;
import org.apache.hello_world_soap_http.DocLitBareGreeterImpl;
import org.apache.hello_world_soap_http.GreeterImpl;
@@ -71,6 +73,13 @@ public class Server extends AbstractBusT
Endpoint ep = Endpoint.publish(address, implementor);
((EndpointImpl)ep).getService().getInInterceptors().add(new URIMappingInterceptor());
eps.add(ep);
+
+ implementor = new GreeterImpl();
+ address = "http://localhost:" + PORT + "/SoapContext/SoapPortWithGzip";
+ Endpoint ep2 = Endpoint.publish(address, implementor);
+ ((EndpointImpl)ep2).getService().getInInterceptors().add(new GZIPInInterceptor());
+ ((EndpointImpl)ep2).getService().getOutInterceptors().add(new GZIPOutInterceptor());
+ eps.add(ep2);
implementor = new RefGreeterImpl();
address = "http://localhost:" + PORT + "/SoapContext/SoapPort2";
@@ -153,7 +162,7 @@ public class Server extends AbstractBusT
portName = "SoapPort",
endpointInterface = "org.apache.cxf.hello_world.elrefs.Greeter",
targetNamespace = "http://apache.org/hello_world_soap_http",
- wsdlLocation = "testutils/hello_world_ref.wsdl")
+ wsdlLocation = "testutils/hello_world_ref.wsdl")
public class RefGreeterImpl implements org.apache.cxf.hello_world.elrefs.Greeter {
public String greetMe(String requestType) {
return "Hello " + requestType;