Added WsdlDefinitionHttpHandler for Java 6 HTTP server.

This commit is contained in:
Arjen Poutsma
2008-02-24 03:28:09 +00:00
parent 249a5a8309
commit 8c555819ae
9 changed files with 98 additions and 16 deletions

View File

@@ -30,8 +30,8 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.ws.server.endpoint.MethodEndpoint;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.soap.addressing.annotation.Action;
import org.springframework.ws.soap.addressing.annotation.Address;
import org.springframework.ws.soap.addressing.server.annotation.Action;
import org.springframework.ws.soap.addressing.server.annotation.Address;
/**
* Implementation of the {@link org.springframework.ws.server.EndpointMapping} interface that uses the {@link Action}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ws.soap.addressing.annotation;
package org.springframework.ws.soap.addressing.server.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.ws.soap.addressing.annotation;
package org.springframework.ws.soap.addressing.server.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -32,8 +32,8 @@ import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.EndpointInvocationChain;
import org.springframework.ws.server.endpoint.MethodEndpoint;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.soap.addressing.annotation.Action;
import org.springframework.ws.soap.addressing.annotation.Address;
import org.springframework.ws.soap.addressing.server.annotation.Action;
import org.springframework.ws.soap.addressing.server.annotation.Address;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;

View File

@@ -46,7 +46,11 @@ public abstract class AbstractActionEndpointMapping extends AbstractAddressingEn
}
protected final Object getEndpointInternal(MessageAddressingProperties map) {
Object endpoint = lookupEndpoint(map.getAction());
URI action = map.getAction();
if (logger.isDebugEnabled()) {
logger.debug("Looking up endpoint for action [" + action + "]");
}
Object endpoint = lookupEndpoint(action);
if (endpoint != null) {
URI endpointAddress = getEndpointAddress(endpoint);
if (endpointAddress == null || endpointAddress.equals(map.getTo())) {

View File

@@ -58,7 +58,7 @@ public class WsAddressing200408 extends AbstractWsAddressingVersion {
return NAMESPACE_URI;
}
protected EndpointReference getDefaultReplyTo(EndpointReference from) {
protected final EndpointReference getDefaultReplyTo(EndpointReference from) {
return from;
}

View File

@@ -115,13 +115,8 @@ public class SoapMessageDispatcher extends MessageDispatcher {
while (headerIterator.hasNext()) {
SoapHeaderElement headerElement = (SoapHeaderElement) headerIterator.next();
QName headerName = headerElement.getName();
if (logger.isDebugEnabled()) {
if (!headerElement.getMustUnderstand()) {
logger.debug("Handling header " + headerName);
}
else {
logger.debug("Handling MustUnderstand header " + headerName);
}
if (headerElement.getMustUnderstand() && logger.isDebugEnabled()) {
logger.debug("Handling MustUnderstand header " + headerName);
}
if (headerElement.getMustUnderstand() && !headerUnderstood(mappedEndpoint, headerElement)) {
notUnderstoodHeaderNames.add(headerName);

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2008 the original author or authors.
*
* Licensed 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.springframework.ws.transport.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
import org.springframework.ws.wsdl.WsdlDefinition;
import org.springframework.xml.transform.TransformerObjectSupport;
/**
* @author Arjen Poutsma
* @since 1.5.0
*/
public class WsdlDefinitionHttpHandler extends TransformerObjectSupport implements HttpHandler, InitializingBean {
private static final String CONTENT_TYPE = "text/xml";
private WsdlDefinition definition;
public WsdlDefinitionHttpHandler() {
}
public WsdlDefinitionHttpHandler(WsdlDefinition definition) {
this.definition = definition;
}
public void setDefinition(WsdlDefinition definition) {
this.definition = definition;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(definition, "'definition' is required");
}
public void handle(HttpExchange httpExchange) throws IOException {
try {
if (HttpTransportConstants.METHOD_GET.equals(httpExchange.getRequestMethod())) {
Headers headers = httpExchange.getResponseHeaders();
headers.set(HttpTransportConstants.HEADER_CONTENT_TYPE, CONTENT_TYPE);
ByteArrayOutputStream os = new ByteArrayOutputStream();
transform(definition.getSource(), new StreamResult(os));
byte[] buf = os.toByteArray();
httpExchange.sendResponseHeaders(HttpTransportConstants.STATUS_OK, buf.length);
FileCopyUtils.copy(buf, httpExchange.getResponseBody());
}
else {
httpExchange.sendResponseHeaders(HttpTransportConstants.STATUS_METHOD_NOT_ALLOWED, -1);
httpExchange.close();
}
}
catch (TransformerException ex) {
logger.error(ex, ex);
}
finally {
httpExchange.close();
}
}
}

View File

@@ -11,7 +11,7 @@
</property>
</bean>
<bean id="webServiceHandler" class="org.springframework.ws.transport.http.WebServiceHttpHandler">
<bean id="webServiceHandler" class="org.springframework.ws.transport.http.WebServiceMessageReceiverHttpHandler">
<property name="chunkedEncoding" value="true"/>
<property name="messageFactory" ref="messageFactory"/>
<property name="messageReceiver" ref="messageDispatcher"/>