Working on client-side support.
This commit is contained in:
@@ -47,7 +47,9 @@ public interface WebServiceMessage {
|
||||
Result getPayloadResult();
|
||||
|
||||
/**
|
||||
* Writes the entire message to the given output stream.
|
||||
* Writes the entire message to the given output stream. If the given stream is an instance of {@link
|
||||
* org.springframework.ws.transport.TransportOutputStream TransportOutputStream}, the corresponding headers will be
|
||||
* writen as well.
|
||||
*
|
||||
* @param outputStream the stream to write to
|
||||
* @throws IOException if an I/O exception occurs
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* The <code>WebServiceMessageFactory</code> serves as factory for {@link org.springframework.ws.WebServiceMessage
|
||||
* WebServiceMessages}. Allows creation of empty messages, or messages based on <code>InputStream</code>s.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see org.springframework.ws.WebServiceMessage
|
||||
*/
|
||||
public interface WebServiceMessageFactory {
|
||||
|
||||
/**
|
||||
* Creates a new, empty {@link WebServiceMessage}.
|
||||
*
|
||||
* @return the empty message
|
||||
*/
|
||||
WebServiceMessage createWebServiceMessage();
|
||||
|
||||
/**
|
||||
* Reads {@link WebServiceMessage} from the given input stream.
|
||||
* <p/>
|
||||
* If the given stream is an instance of {@link org.springframework.ws.transport.TransportOutputStream
|
||||
* TransportOutputStream}, the headers will be read from the request.
|
||||
*
|
||||
* @param inputStream the inputstream to read the message from
|
||||
* @return the created message
|
||||
* @throws java.io.IOException if an I/O exception occurs
|
||||
*/
|
||||
WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the <code>MessageContext</code> interface. Contains functionality to set and remove
|
||||
* properties.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractMessageContext implements MessageContext {
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
private WebServiceMessage response;
|
||||
|
||||
private final TransportRequest transportRequest;
|
||||
|
||||
/**
|
||||
* Keys are <code>Strings</code>, values are <code>Objects</code>. Lazily initalized by
|
||||
* <code>getProperties()</code>.
|
||||
*/
|
||||
private Map properties;
|
||||
|
||||
/**
|
||||
* Construct a new instance of the <code>AbstractMessageContext</code> with the given request message and
|
||||
* transportRequest.
|
||||
*/
|
||||
protected AbstractMessageContext(WebServiceMessage request, TransportRequest transportRequest) {
|
||||
Assert.notNull(request, "No request given");
|
||||
Assert.notNull(transportRequest, "No transport request given");
|
||||
this.request = request;
|
||||
this.transportRequest = transportRequest;
|
||||
}
|
||||
|
||||
public final WebServiceMessage getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method that sets the request message directly.
|
||||
*/
|
||||
protected final void setRequest(WebServiceMessage request) {
|
||||
Assert.notNull(request);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public final WebServiceMessage getResponse() {
|
||||
if (response == null) {
|
||||
response = createResponseMessage();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public final boolean hasResponse() {
|
||||
return response != null;
|
||||
}
|
||||
|
||||
public final TransportRequest getTransportRequest() {
|
||||
return transportRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method that sets the response message directly.
|
||||
*/
|
||||
protected final void setResponse(WebServiceMessage response) {
|
||||
Assert.notNull(response);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
private Map getProperties() {
|
||||
if (properties == null) {
|
||||
properties = new HashMap();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public boolean containsProperty(String name) {
|
||||
return getProperties().containsKey(name);
|
||||
}
|
||||
|
||||
public Object getProperty(String name) {
|
||||
return getProperties().get(name);
|
||||
}
|
||||
|
||||
public String[] getPropertyNames() {
|
||||
return (String[]) getProperties().keySet().toArray(new String[getProperties().size()]);
|
||||
}
|
||||
|
||||
public void removeProperty(String name) {
|
||||
getProperties().remove(name);
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value) {
|
||||
getProperties().put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract template method that creates a new <code>WebServiceMessage</code>.
|
||||
*/
|
||||
protected abstract WebServiceMessage createResponseMessage();
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright 2006 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.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Simple implementation of <code>MessageContext</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class DefaultMessageContext implements MessageContext {
|
||||
|
||||
private final WebServiceMessageFactory messageFactory;
|
||||
|
||||
/**
|
||||
* Keys are <code>Strings</code>, values are <code>Objects</code>. Lazily initalized by
|
||||
* <code>getProperties()</code>.
|
||||
*/
|
||||
private Map properties;
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
private WebServiceMessage response;
|
||||
|
||||
/**
|
||||
* Construct a new, empty instance of the <code>DefaultMessageContext</code> with the given message factory.
|
||||
*/
|
||||
public DefaultMessageContext(WebServiceMessageFactory messageFactory) {
|
||||
this(messageFactory.createWebServiceMessage(), messageFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new instance of the <code>DefaultMessageContext</code> with the given request message and message
|
||||
* factory.
|
||||
*/
|
||||
public DefaultMessageContext(WebServiceMessage request, WebServiceMessageFactory messageFactory) {
|
||||
Assert.notNull(request, "No request given");
|
||||
Assert.notNull(messageFactory, "messageFactory must not be null");
|
||||
this.request = request;
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
private Map getProperties() {
|
||||
if (properties == null) {
|
||||
properties = new HashMap();
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request message.
|
||||
*
|
||||
* @return the request message
|
||||
*/
|
||||
public WebServiceMessage getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response message. Creates a new response if no response is present.
|
||||
*
|
||||
* @return the response message
|
||||
* @see #hasResponse()
|
||||
*/
|
||||
public WebServiceMessage getResponse() {
|
||||
if (response == null) {
|
||||
response = messageFactory.createWebServiceMessage();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this message context contains a property with the given name.
|
||||
*
|
||||
* @param name the name of the property to look fo
|
||||
* @return <code>true</code> if the <code>MessageContext</code> contains the property; <code>false</code> otherwise
|
||||
*/
|
||||
public boolean containsProperty(String name) {
|
||||
return getProperties().containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a specific property from the <code>MessageContext</code>.
|
||||
*
|
||||
* @param name name of the property whose value is to be retrieved
|
||||
* @return value of the property
|
||||
*/
|
||||
public Object getProperty(String name) {
|
||||
return getProperties().get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of all properties in this <code>MessageContext</code>.
|
||||
*
|
||||
* @return the names of all properties in this context, or an empty array if none defined
|
||||
*/
|
||||
public String[] getPropertyNames() {
|
||||
return (String[]) getProperties().keySet().toArray(new String[getProperties().size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this context has a resonse.
|
||||
*
|
||||
* @return <code>true</code> if this context has a response; <code>false</code> otherwise
|
||||
*/
|
||||
public boolean hasResponse() {
|
||||
return response != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a property from the <code>MessageContext</code>.
|
||||
*
|
||||
* @param name name of the property to be removed
|
||||
*/
|
||||
public void removeProperty(String name) {
|
||||
getProperties().remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name and value of a property associated with the <code>MessageContext</code>. If the
|
||||
* <code>MessageContext</code> contains a value of the same property, the old value is replaced.
|
||||
*
|
||||
* @param name name of the property associated with the value
|
||||
* @param value value of the property
|
||||
*/
|
||||
public void setProperty(String name, Object value) {
|
||||
getProperties().put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,13 @@
|
||||
|
||||
package org.springframework.ws.context;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* Context holder for message requests. Contains both the message request as well as the response. Response message are
|
||||
* usually lazily created.
|
||||
* <p/>
|
||||
* <code>MessageContext</code> implementations are constructed using a <code>MessageContextFactory</code>, taking a
|
||||
* <code>TransportContext</code> as a parameter.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see MessageContextFactory#createContext(org.springframework.ws.transport.TransportContext)
|
||||
*/
|
||||
public interface MessageContext {
|
||||
|
||||
@@ -56,21 +48,6 @@ public interface MessageContext {
|
||||
*/
|
||||
boolean hasResponse();
|
||||
|
||||
/**
|
||||
* Returns the transport request used to create this context. Call be used for URL-based message routing.
|
||||
*
|
||||
* @return the transport request
|
||||
*/
|
||||
TransportRequest getTransportRequest();
|
||||
|
||||
/**
|
||||
* Sends the response to the given transport response.
|
||||
*
|
||||
* @param transportResponse the transport used for sending
|
||||
* @throws IOException if an I/O exception occurs
|
||||
*/
|
||||
void sendResponse(TransportResponse transportResponse) throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the name and value of a property associated with the <code>MessageContext</code>. If the
|
||||
* <code>MessageContext</code> contains a value of the same property, the old value is replaced.
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005 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.context;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
|
||||
/**
|
||||
* The <code>MessageContextFactory</code> serves as factory for <code>MessageContext</code>s. Allows creation of
|
||||
* contexts based on <code>TransportRequest</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface MessageContextFactory {
|
||||
|
||||
/**
|
||||
* Creates a <code>MessageContext</code> based on the given transport context. Implementations use the context
|
||||
* request's input stream to create a request message, and possibly copy the request headers to the message.
|
||||
* <p/>
|
||||
* Implementations are free to store the transport context for later reference. For instance, streaming
|
||||
* implementations of <code>MessageContextFactory</code> might use the transport response to directly write a
|
||||
* response message.
|
||||
*
|
||||
* @param transportContext the transport context which contains the request
|
||||
* @return the created message context
|
||||
* @throws IOException if an I/O exception occurs
|
||||
*/
|
||||
MessageContext createContext(TransportContext transportContext) throws IOException;
|
||||
|
||||
}
|
||||
@@ -37,7 +37,7 @@ import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapFault;
|
||||
import org.springframework.ws.soap.SoapFaultDetail;
|
||||
import org.springframework.ws.soap.SoapFaultDetailElement;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
@@ -239,8 +239,8 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup
|
||||
for (int i = 0; i < errors.length; i++) {
|
||||
logger.warn("XML validation error on request: " + errors[i].getMessage());
|
||||
}
|
||||
if (messageContext instanceof SoapMessageContext) {
|
||||
createRequestValidationFault((SoapMessageContext) messageContext, errors);
|
||||
if (messageContext.getResponse() instanceof SoapMessage) {
|
||||
createRequestValidationFault((SoapMessage) messageContext.getResponse(), errors);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -296,9 +296,9 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup
|
||||
/**
|
||||
* Creates a response soap message containing a <code>SoapFault</code> that descibes the validation errors.
|
||||
*/
|
||||
protected void createRequestValidationFault(SoapMessageContext context, SAXParseException[] errors)
|
||||
protected void createRequestValidationFault(SoapMessage response, SAXParseException[] errors)
|
||||
throws TransformerException {
|
||||
SoapBody body = context.getSoapResponse().getSoapBody();
|
||||
SoapBody body = response.getSoapBody();
|
||||
SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason(), getFaultStringOrReasonLocale());
|
||||
if (getAddValidationErrorDetail()) {
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.pox.context;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.AbstractMessageContext;
|
||||
import org.springframework.ws.pox.PoxMessage;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the <code>PoxMessageContext</code> interface. Implements base <code>MessageContext</code>
|
||||
* methods by delegating to <code>PoxMessageContext</code> functionality.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractPoxMessageContext extends AbstractMessageContext implements PoxMessageContext {
|
||||
|
||||
protected AbstractPoxMessageContext(PoxMessage request, TransportRequest transportRequest) {
|
||||
super(request, transportRequest);
|
||||
}
|
||||
|
||||
public final PoxMessage getPoxResponse() {
|
||||
return (PoxMessage) getResponse();
|
||||
}
|
||||
|
||||
public final PoxMessage getPoxRequest() {
|
||||
return (PoxMessage) getRequest();
|
||||
}
|
||||
|
||||
protected final WebServiceMessage createResponseMessage() {
|
||||
return createResponsePoxMessage();
|
||||
}
|
||||
|
||||
protected abstract PoxMessage createResponsePoxMessage();
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.springframework.ws.pox.PoxMessage;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,8 @@ import org.w3c.dom.Document;
|
||||
*/
|
||||
public class DomPoxMessage implements PoxMessage {
|
||||
|
||||
private static final String CONTENT_TYPE = "text/xml";
|
||||
|
||||
private final Document document;
|
||||
|
||||
private Transformer transformer;
|
||||
@@ -68,10 +71,14 @@ public class DomPoxMessage implements PoxMessage {
|
||||
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
try {
|
||||
if (outputStream instanceof TransportOutputStream) {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
transportOutputStream.addHeader("Content-Type", CONTENT_TYPE);
|
||||
}
|
||||
transformer.transform(getPayloadSource(), new StreamResult(outputStream));
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
throw new DomPoxMessageException("Could not create transformer", ex);
|
||||
throw new DomPoxMessageException("Could write document: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.pox.dom;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.transform.Transformer;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.pox.PoxMessage;
|
||||
import org.springframework.ws.pox.context.AbstractPoxMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>MessageContext</code> that contains a <code>DomPoxMessage</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see DomPoxMessage
|
||||
*/
|
||||
public class DomPoxMessageContext extends AbstractPoxMessageContext {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
/**
|
||||
* Creates a new <code>DomPoxMessageContext</code> with the given parameters.
|
||||
*/
|
||||
public DomPoxMessageContext(Document request,
|
||||
TransportRequest transportRequest,
|
||||
DocumentBuilder documentBuilder,
|
||||
Transformer transformer) {
|
||||
super(new DomPoxMessage(request, transformer), transportRequest);
|
||||
Assert.notNull(documentBuilder, "documentBuilder must not be null");
|
||||
Assert.notNull(transformer, "transformer must not be null");
|
||||
this.documentBuilder = documentBuilder;
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
protected PoxMessage createResponsePoxMessage() {
|
||||
Document document = documentBuilder.newDocument();
|
||||
return new DomPoxMessage(document, transformer);
|
||||
}
|
||||
|
||||
public void sendResponse(TransportResponse transportResponse) throws IOException {
|
||||
if (hasResponse()) {
|
||||
transportResponse.addHeader("Content-Type", "text/xml");
|
||||
getResponse().writeTo(transportResponse.getOutputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.ws.pox.dom;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -24,20 +25,19 @@ import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>MessageContextFactory</code> interface that creates a DOM
|
||||
* Implementation of the {@link org.springframework.ws.WebServiceMessageFactory WebServiceMessageFactory} interinterface
|
||||
* that creates a DOM PoxMessage.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see DomPoxMessageContext
|
||||
* @see org.springframework.ws.pox.dom.DomPoxMessage
|
||||
*/
|
||||
public class DomPoxMessageContextFactory implements MessageContextFactory, InitializingBean {
|
||||
public class DomPoxMessageFactory implements WebServiceMessageFactory, InitializingBean {
|
||||
|
||||
private DocumentBuilderFactory documentBuilderFactory;
|
||||
|
||||
@@ -68,15 +68,25 @@ public class DomPoxMessageContextFactory implements MessageContextFactory, Initi
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
}
|
||||
|
||||
public MessageContext createContext(TransportContext transportContext) throws IOException {
|
||||
TransportRequest transportRequest = transportContext.getTransportRequest();
|
||||
public WebServiceMessage createWebServiceMessage() {
|
||||
try {
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document request = documentBuilder.parse(transportRequest.getInputStream());
|
||||
return new DomPoxMessageContext(request,
|
||||
transportRequest,
|
||||
documentBuilder,
|
||||
transformerFactory.newTransformer());
|
||||
Document request = documentBuilder.newDocument();
|
||||
return new DomPoxMessage(request, transformerFactory.newTransformer());
|
||||
}
|
||||
catch (ParserConfigurationException ex) {
|
||||
throw new DomPoxMessageException("Could not create message context", ex);
|
||||
}
|
||||
catch (TransformerConfigurationException ex) {
|
||||
throw new DomPoxMessageException("Could not create transormer", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document request = documentBuilder.parse(inputStream);
|
||||
return new DomPoxMessage(request, transformerFactory.newTransformer());
|
||||
}
|
||||
catch (ParserConfigurationException ex) {
|
||||
throw new DomPoxMessageException("Could not create message context", ex);
|
||||
@@ -29,7 +29,6 @@ import org.springframework.ws.EndpointInterceptor;
|
||||
import org.springframework.ws.EndpointInvocationChain;
|
||||
import org.springframework.ws.MessageDispatcher;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.soap.endpoint.SimpleSoapExceptionResolver;
|
||||
import org.springframework.ws.soap.soap12.Soap12Header;
|
||||
|
||||
@@ -95,19 +94,19 @@ public class SoapMessageDispatcher extends MessageDispatcher {
|
||||
* @see SoapHeader#examineMustUnderstandHeaderElements(String)
|
||||
*/
|
||||
protected boolean handleRequest(EndpointInvocationChain mappedEndpoint, MessageContext messageContext) {
|
||||
if (messageContext instanceof SoapMessageContext) {
|
||||
SoapMessageContext soapContext = (SoapMessageContext) messageContext;
|
||||
if (soapContext.getSoapRequest().getSoapHeader() == null) {
|
||||
if (messageContext.getRequest() instanceof SoapMessage) {
|
||||
SoapMessage soapRequest = (SoapMessage) messageContext.getRequest();
|
||||
if (soapRequest.getSoapHeader() == null) {
|
||||
// no headers to process
|
||||
return true;
|
||||
}
|
||||
String[] roles = getRoles(mappedEndpoint, soapContext.getSoapRequest().getVersion());
|
||||
String[] roles = getRoles(mappedEndpoint, soapRequest.getVersion());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Handling MustUnderstand headers for actors/roles [" +
|
||||
StringUtils.arrayToCommaDelimitedString(roles));
|
||||
}
|
||||
for (int i = 0; i < roles.length; i++) {
|
||||
if (!handleRequestForRole(mappedEndpoint, soapContext, roles[i])) {
|
||||
if (!handleRequestForRole(mappedEndpoint, messageContext, roles[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -142,9 +141,9 @@ public class SoapMessageDispatcher extends MessageDispatcher {
|
||||
* @see SoapEndpointInterceptor#understands(SoapHeaderElement)
|
||||
*/
|
||||
private boolean handleRequestForRole(EndpointInvocationChain mappedEndpoint,
|
||||
SoapMessageContext messageContext,
|
||||
MessageContext messageContext,
|
||||
String actorOrRole) {
|
||||
SoapHeader requestHeader = messageContext.getSoapRequest().getSoapHeader();
|
||||
SoapHeader requestHeader = ((SoapMessage) messageContext.getRequest()).getSoapHeader();
|
||||
List notUnderstoodHeaderNames = new ArrayList();
|
||||
for (Iterator iterator = requestHeader.examineMustUnderstandHeaderElements(actorOrRole); iterator.hasNext();) {
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
@@ -174,10 +173,11 @@ public class SoapMessageDispatcher extends MessageDispatcher {
|
||||
logger.warn("Could not handle mustUnderstand headers: " +
|
||||
StringUtils.collectionToCommaDelimitedString(notUnderstoodHeaderNames) + ". Returning fault");
|
||||
}
|
||||
SoapBody responseBody = messageContext.getSoapResponse().getSoapBody();
|
||||
SoapMessage soapResponse = (SoapMessage) messageContext.getResponse();
|
||||
SoapBody responseBody = soapResponse.getSoapBody();
|
||||
SoapFault fault = responseBody.addMustUnderstandFault(mustUnderstandFault, mustUnderstandFaultLocale);
|
||||
fault.setFaultActorOrRole(actorOrRole);
|
||||
SoapHeader header = messageContext.getSoapResponse().getSoapHeader();
|
||||
SoapHeader header = soapResponse.getSoapHeader();
|
||||
if (header instanceof Soap12Header) {
|
||||
Soap12Header soap12Header = (Soap12Header) header;
|
||||
for (Iterator iterator = notUnderstoodHeaderNames.iterator(); iterator.hasNext();) {
|
||||
@@ -206,9 +206,9 @@ public class SoapMessageDispatcher extends MessageDispatcher {
|
||||
if (mappedEndpoint != null && messageContext.hasResponse() &&
|
||||
!ObjectUtils.isEmpty(mappedEndpoint.getInterceptors())) {
|
||||
boolean hasFault = false;
|
||||
if (messageContext instanceof SoapMessageContext) {
|
||||
SoapMessageContext soapMessageContext = (SoapMessageContext) messageContext;
|
||||
hasFault = soapMessageContext.getSoapResponse().getSoapBody().hasFault();
|
||||
if (messageContext.getResponse() instanceof SoapMessage) {
|
||||
SoapMessage soapResponse = (SoapMessage) messageContext.getResponse();
|
||||
hasFault = soapResponse.getSoapBody().hasFault();
|
||||
}
|
||||
boolean resume = true;
|
||||
for (int i = interceptorIndex; resume && i >= 0; i--) {
|
||||
|
||||
@@ -41,25 +41,25 @@ public interface SoapVersion {
|
||||
|
||||
private static final String CONTENT_TYPE = "text/xml";
|
||||
|
||||
private final QName ENVELOPE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Envelope");
|
||||
private QName ENVELOPE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Envelope");
|
||||
|
||||
private final QName HEADER_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Header");
|
||||
private QName HEADER_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Header");
|
||||
|
||||
private final QName BODY_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Body");
|
||||
private QName BODY_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Body");
|
||||
|
||||
private final QName FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Fault");
|
||||
private QName FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Fault");
|
||||
|
||||
private final QName MUST_UNDERSTAND_ATTRIBUTE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "mustUnderstand");
|
||||
private QName MUST_UNDERSTAND_ATTRIBUTE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "mustUnderstand");
|
||||
|
||||
private final QName ACTOR_NAME = new QName(ENVELOPE_NAMESPACE_URI, "actor");
|
||||
private QName ACTOR_NAME = new QName(ENVELOPE_NAMESPACE_URI, "actor");
|
||||
|
||||
private final QName CLIENT_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Client");
|
||||
private QName CLIENT_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Client");
|
||||
|
||||
private final QName SERVER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Server");
|
||||
private QName SERVER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Server");
|
||||
|
||||
private final QName MUST_UNDERSTAND_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "MustUnderstand");
|
||||
private QName MUST_UNDERSTAND_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "MustUnderstand");
|
||||
|
||||
private final QName VERSION_MISMATCH_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "VersionMismatch");
|
||||
private QName VERSION_MISMATCH_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "VersionMismatch");
|
||||
|
||||
public QName getBodyName() {
|
||||
return BODY_NAME;
|
||||
@@ -143,25 +143,25 @@ public interface SoapVersion {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/soap+xml";
|
||||
|
||||
private final QName ENVELOPE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Envelope");
|
||||
private QName ENVELOPE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Envelope");
|
||||
|
||||
private final QName HEADER_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Header");
|
||||
private QName HEADER_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Header");
|
||||
|
||||
private final QName BODY_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Body");
|
||||
private QName BODY_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Body");
|
||||
|
||||
private final QName FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Fault");
|
||||
private QName FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Fault");
|
||||
|
||||
private final QName MUST_UNDERSTAND_ATTRIBUTE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "mustUnderstand");
|
||||
private QName MUST_UNDERSTAND_ATTRIBUTE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "mustUnderstand");
|
||||
|
||||
private final QName ROLE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "role");
|
||||
private QName ROLE_NAME = new QName(ENVELOPE_NAMESPACE_URI, "role");
|
||||
|
||||
private final QName SENDER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Sender");
|
||||
private QName SENDER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Sender");
|
||||
|
||||
private final QName RECEIVER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Receiver");
|
||||
private QName RECEIVER_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "Receiver");
|
||||
|
||||
private final QName MUST_UNDERSTAND_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "MustUnderstand");
|
||||
private QName MUST_UNDERSTAND_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "MustUnderstand");
|
||||
|
||||
private final QName VERSION_MISMATCH_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "VersionMismatch");
|
||||
private QName VERSION_MISMATCH_FAULT_NAME = new QName(ENVELOPE_NAMESPACE_URI, "VersionMismatch");
|
||||
|
||||
public QName getBodyName() {
|
||||
return BODY_NAME;
|
||||
|
||||
@@ -20,24 +20,24 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.apache.axiom.attachments.Attachments;
|
||||
import org.apache.axiom.attachments.Part;
|
||||
import org.apache.axiom.om.OMException;
|
||||
import org.apache.axiom.om.OMOutputFormat;
|
||||
import org.apache.axiom.soap.SOAPEnvelope;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.apache.axiom.soap.SOAPProcessingException;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.soap.AbstractSoapMessage;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
* AXIOM-specific implementation of the <code>SoapMessage</code> interface. Accessed via the
|
||||
@@ -48,7 +48,6 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see SOAPMessage
|
||||
* @see AxiomSoapMessageContext
|
||||
*/
|
||||
public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
|
||||
@@ -79,6 +78,19 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
* Create a new <code>AxiomSoapMessage</code> based on the given AXIOM <code>SOAPMessage</code>.
|
||||
*
|
||||
* @param soapMessage the AXIOM SOAPMessage
|
||||
* @param payloadCaching whether the contents of the SOAP body should be cached or not
|
||||
*/
|
||||
public AxiomSoapMessage(SOAPMessage soapMessage, boolean payloadCaching) {
|
||||
axiomMessage = soapMessage;
|
||||
axiomFactory = (SOAPFactory) soapMessage.getSOAPEnvelope().getOMFactory();
|
||||
attachments = null;
|
||||
this.payloadCaching = payloadCaching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>AxiomSoapMessage</code> based on the given AXIOM <code>SOAPMessage</code> and attachments.
|
||||
*
|
||||
* @param soapMessage the AXIOM SOAPMessage
|
||||
* @param attachments the attachments
|
||||
* @param payloadCaching whether the contents of the SOAP body should be cached or not
|
||||
*/
|
||||
@@ -138,7 +150,18 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
try {
|
||||
axiomMessage.serialize(outputStream);
|
||||
String charsetEncoding = axiomMessage.getCharsetEncoding();
|
||||
|
||||
OMOutputFormat format = new OMOutputFormat();
|
||||
format.setCharSetEncoding(charsetEncoding);
|
||||
format.setSOAP11(getVersion() == SoapVersion.SOAP_11);
|
||||
if (outputStream instanceof TransportOutputStream) {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
String contentType = format.getContentType();
|
||||
contentType += "; charset=\"" + charsetEncoding + "\"";
|
||||
transportOutputStream.addHeader("Content-Type", contentType);
|
||||
}
|
||||
axiomMessage.serializeAndConsume(outputStream, format);
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.axiom;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.apache.axiom.om.OMOutputFormat;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.context.AbstractSoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* AXIOM-specific implementation of the <code>SoapMessageContext</code> interface. Created by the
|
||||
* <code>AxiomSoapMessageContextFactory</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see AxiomSoapMessageContextFactory
|
||||
*/
|
||||
public class AxiomSoapMessageContext extends AbstractSoapMessageContext {
|
||||
|
||||
/**
|
||||
* Creates a new instance based on the given Axiom request message, and a SOAP factory.
|
||||
*
|
||||
* @param messageRequest the request message
|
||||
*/
|
||||
public AxiomSoapMessageContext(AxiomSoapMessage messageRequest, TransportRequest transportRequest) {
|
||||
super(messageRequest, transportRequest);
|
||||
}
|
||||
|
||||
protected SoapMessage createResponseSoapMessage() {
|
||||
SOAPFactory soapFactory = (SOAPFactory) getAxiomRequest().getSOAPEnvelope().getOMFactory();
|
||||
return new AxiomSoapMessage(soapFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request as an Axiom SOAP message.
|
||||
*/
|
||||
public SOAPMessage getAxiomRequest() {
|
||||
return ((AxiomSoapMessage) getSoapRequest()).getAxiomMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response as an Axiom SOAP message.
|
||||
*/
|
||||
public SOAPMessage getAxiomResponse() {
|
||||
return ((AxiomSoapMessage) getSoapResponse()).getAxiomMessage();
|
||||
}
|
||||
|
||||
public void sendResponse(TransportResponse transportResponse) throws IOException {
|
||||
try {
|
||||
if (hasResponse()) {
|
||||
AxiomSoapMessage response = (AxiomSoapMessage) getSoapResponse();
|
||||
SOAPMessage axiomResponse = response.getAxiomMessage();
|
||||
String charsetEncoding = axiomResponse.getCharsetEncoding();
|
||||
|
||||
OMOutputFormat format = new OMOutputFormat();
|
||||
format.setCharSetEncoding(charsetEncoding);
|
||||
format.setSOAP11(response.getVersion() == SoapVersion.SOAP_11);
|
||||
String contentType = format.getContentType();
|
||||
contentType += "; charset=\"" + charsetEncoding + "\"";
|
||||
|
||||
transportResponse.addHeader("Content-Type", contentType);
|
||||
axiomResponse.serializeAndConsume(transportResponse.getOutputStream(), format);
|
||||
}
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw new AxiomSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,49 +38,49 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.soap.SoapMessageCreationException;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
/**
|
||||
* Axiom-specific implementation of the <code>MessageContextFactory</code> interface. Creates a
|
||||
* <code>AxiomSoapMessageContext</code>.
|
||||
* Axiom-specific implementation of the {@link org.springframework.ws.WebServiceMessageFactory WebServiceMessageFactory}
|
||||
* interface. Creates {@link org.springframework.ws.soap.axiom.AxiomSoapMessage AxiomSoapMessages}.
|
||||
* <p/>
|
||||
* To increase reading performance on the the SOAP request created by this message context factory, you can set the
|
||||
* <code>payloadCaching</code> property to <code>false</code> (default is <code>true</code>). This this will read the
|
||||
* contents of the body directly from the <code>TransportRequest</code>. However, <strong>when this setting is enabled,
|
||||
* the payload can only be read once</strong>. This means that any endpoint mappings or interceptors which are based on
|
||||
* the message payload (such as the <code>PayloadRootQNameEndpointMapping</code>, the
|
||||
* <code>PayloadValidatingInterceptor</code>, or the <code>PayloadLoggingInterceptor</code>) cannot be used. Instead,
|
||||
* use an endpoint mapping that does not consume the payload (i.e. the <code>SoapActionEndpointMapping</code>).
|
||||
* contents of the body directly from the stream. However, <strong>when this setting is enabled, the payload can only be
|
||||
* read once</strong>. This means that any endpoint mappings or interceptors which are based on the message payload
|
||||
* (such as the <code>PayloadRootQNameEndpointMapping</code>, the <code>PayloadValidatingInterceptor</code>, or the
|
||||
* <code>PayloadLoggingInterceptor</code>) cannot be used. Instead, use an endpoint mapping that does not consume the
|
||||
* payload (i.e. the <code>SoapActionEndpointMapping</code>).
|
||||
* <p/>
|
||||
* Mostly derived from <code>org.apache.axis2.transport.http.HTTPTransportUtils</code> and
|
||||
* <code>org.apache.axis2.transport.TransportUtils</code>, which we cannot use since they are not part of the Axiom
|
||||
* distribution.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see AxiomSoapMessageContext
|
||||
* @see AxiomSoapMessage
|
||||
* @see #setPayloadCaching(boolean)
|
||||
*/
|
||||
public class AxiomSoapMessageContextFactory implements MessageContextFactory, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AxiomSoapMessageContextFactory.class);
|
||||
public class AxiomSoapMessageFactory implements WebServiceMessageFactory, InitializingBean {
|
||||
|
||||
private static final String CHAR_SET_ENCODING = "charset";
|
||||
|
||||
private static final String DEFAULT_CHAR_SET_ENCODING = "UTF-8";
|
||||
|
||||
private static final String CONTENT_TYPE_HEADER = "Content-Type";
|
||||
|
||||
private static final String DEFAULT_CHAR_SET_ENCODING = "UTF-8";
|
||||
|
||||
private static final String MULTI_PART_RELATED_CONTENT_TYPE = "multipart/related";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AxiomSoapMessageFactory.class);
|
||||
|
||||
private XMLInputFactory inputFactory;
|
||||
|
||||
private boolean payloadCaching = true;
|
||||
|
||||
private SOAP11Factory soap11Factory;
|
||||
private SOAP11Factory soap11Factory = new SOAP11Factory();
|
||||
|
||||
private SOAP12Factory soap12Factory;
|
||||
private SOAP12Factory soap12Factory = new SOAP12Factory();
|
||||
|
||||
/**
|
||||
* Indicates whether the SOAP Body payload should be cached or not. Default is <code>true</code>. Setting this to
|
||||
@@ -91,54 +91,67 @@ public class AxiomSoapMessageContextFactory implements MessageContextFactory, In
|
||||
this.payloadCaching = payloadCaching;
|
||||
}
|
||||
|
||||
private XMLInputFactory inputFactory;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
inputFactory = XMLInputFactory.newInstance();
|
||||
soap11Factory = new SOAP11Factory();
|
||||
soap12Factory = new SOAP12Factory();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(payloadCaching ? "Enabled payload caching" : "Disabled payload caching");
|
||||
}
|
||||
}
|
||||
|
||||
public MessageContext createContext(TransportContext transportContext) throws IOException {
|
||||
TransportRequest transportRequest = transportContext.getTransportRequest();
|
||||
Iterator iterator = transportRequest.getHeaders(CONTENT_TYPE_HEADER);
|
||||
Assert.isTrue(iterator.hasNext(), "No " + CONTENT_TYPE_HEADER + " header present of TransportRequest");
|
||||
String contentType = (String) iterator.next();
|
||||
public WebServiceMessage createWebServiceMessage() {
|
||||
return new AxiomSoapMessage(soap11Factory);
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
String contentType = null;
|
||||
if (inputStream instanceof TransportInputStream) {
|
||||
TransportInputStream transportInputStream = (TransportInputStream) inputStream;
|
||||
Iterator iterator = transportInputStream.getHeaders(CONTENT_TYPE_HEADER);
|
||||
Assert.isTrue(iterator.hasNext(), "No " + CONTENT_TYPE_HEADER + " header present of TransportRequest");
|
||||
contentType = (String) iterator.next();
|
||||
}
|
||||
Assert.hasLength(contentType, "No " + CONTENT_TYPE_HEADER + " header present of TransportRequest");
|
||||
InputStream inputStream = transportRequest.getInputStream();
|
||||
try {
|
||||
AxiomSoapMessage requestMessage;
|
||||
if (contentType.indexOf(MULTI_PART_RELATED_CONTENT_TYPE) == -1) {
|
||||
XMLStreamReader reader =
|
||||
inputFactory.createXMLStreamReader(inputStream, getCharSetEncoding(contentType));
|
||||
SOAPFactory soapFactory = getSoapFactory(contentType);
|
||||
StAXSOAPModelBuilder builder =
|
||||
new StAXSOAPModelBuilder(reader, soapFactory, soapFactory.getSoapVersionURI());
|
||||
requestMessage = createAxiomSoapMessage(builder, null);
|
||||
if (isMultiPartRelated(contentType)) {
|
||||
return createMultiPartAxiomSoapMessage(inputStream, contentType);
|
||||
}
|
||||
else {
|
||||
requestMessage = createMultiPartAxiomSoapMessage(inputStream, contentType);
|
||||
return createAxiomSoapMessage(inputStream, contentType);
|
||||
}
|
||||
return new AxiomSoapMessageContext(requestMessage, transportRequest);
|
||||
|
||||
}
|
||||
catch (XMLStreamException ex) {
|
||||
throw new SoapMessageCreationException("Could not create message: " + ex.getMessage(), ex);
|
||||
throw new AxiomSoapMessageCreationException("Could not parse request: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (OMException ex) {
|
||||
throw new SoapMessageCreationException("Could not create message: " + ex.getMessage(), ex);
|
||||
throw new AxiomSoapMessageCreationException("Could not create message: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMultiPartRelated(String contentType) {
|
||||
return contentType.indexOf(MULTI_PART_RELATED_CONTENT_TYPE) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AxiomSoapMessage without attachments.
|
||||
*/
|
||||
private WebServiceMessage createAxiomSoapMessage(InputStream inputStream, String contentType)
|
||||
throws XMLStreamException {
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream, getCharSetEncoding(contentType));
|
||||
SOAPFactory soapFactory = getSoapFactory(contentType);
|
||||
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader, soapFactory, soapFactory.getSoapVersionURI());
|
||||
SOAPMessage soapMessage = builder.getSoapMessage();
|
||||
return new AxiomSoapMessage(soapMessage, payloadCaching);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AxiomSoapMessage with attachments.
|
||||
*/
|
||||
private AxiomSoapMessage createMultiPartAxiomSoapMessage(InputStream inputStream, String contentType)
|
||||
throws XMLStreamException {
|
||||
Attachments attachments = new Attachments(inputStream, contentType);
|
||||
if (!(attachments.getAttachmentSpecType().equals(MTOMConstants.SWA_TYPE) ||
|
||||
attachments.getAttachmentSpecType().equals(MTOMConstants.MTOM_TYPE))) {
|
||||
throw new SoapMessageCreationException(
|
||||
throw new AxiomSoapMessageCreationException(
|
||||
"Unknown attachment type: [" + attachments.getAttachmentSpecType() + "]");
|
||||
}
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(attachments.getSOAPPartInputStream(),
|
||||
@@ -154,18 +167,6 @@ public class AxiomSoapMessageContextFactory implements MessageContextFactory, In
|
||||
return new AxiomSoapMessage(builder.getSoapMessage(), attachments, payloadCaching);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>AxiomSoapMessage</code> based on the given parameters.
|
||||
*
|
||||
* @param modelBuilder the builder used to optain the Axiom SOAPMessage
|
||||
* @param attachments the attachments, can be <code>null</code>
|
||||
* @return the created message
|
||||
*/
|
||||
private AxiomSoapMessage createAxiomSoapMessage(StAXSOAPModelBuilder modelBuilder, Attachments attachments) {
|
||||
SOAPMessage soapMessage = modelBuilder.getSoapMessage();
|
||||
return new AxiomSoapMessage(soapMessage, attachments, payloadCaching);
|
||||
}
|
||||
|
||||
private SOAPFactory getSoapFactory(String contentType) {
|
||||
if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) != -1) {
|
||||
return soap11Factory;
|
||||
@@ -174,7 +175,7 @@ public class AxiomSoapMessageContextFactory implements MessageContextFactory, In
|
||||
return soap12Factory;
|
||||
}
|
||||
else {
|
||||
throw new SoapMessageCreationException("Unknown content type '" + contentType + "'");
|
||||
throw new AxiomSoapMessageCreationException("Unknown content type '" + contentType + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,4 +210,5 @@ public class AxiomSoapMessageContextFactory implements MessageContextFactory, In
|
||||
return value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.AbstractMessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the <code>SoapMessageContext</code> interface. Implements base <code>MessageContext</code>
|
||||
* methods by delegating to <code>SoapMessageContext</code> functionality.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractSoapMessageContext extends AbstractMessageContext implements SoapMessageContext {
|
||||
|
||||
protected AbstractSoapMessageContext(SoapMessage request, TransportRequest transportRequest) {
|
||||
super(request, transportRequest);
|
||||
}
|
||||
|
||||
public final SoapMessage getSoapResponse() {
|
||||
return (SoapMessage) getResponse();
|
||||
}
|
||||
|
||||
public final SoapMessage getSoapRequest() {
|
||||
return (SoapMessage) getRequest();
|
||||
}
|
||||
|
||||
protected final WebServiceMessage createResponseMessage() {
|
||||
return createResponseSoapMessage();
|
||||
}
|
||||
|
||||
protected abstract SoapMessage createResponseSoapMessage();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
/**
|
||||
* SOAP-specific extension of the <code>MessageContext</code> interface. Contains methods to obtain
|
||||
* <code>SoapMessage</code>s instead of <code>WebServiceMessage</code>s.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface SoapMessageContext extends MessageContext {
|
||||
|
||||
/**
|
||||
* Returns the request SOAP message.
|
||||
*
|
||||
* @return the request message
|
||||
*/
|
||||
SoapMessage getSoapRequest();
|
||||
|
||||
/**
|
||||
* Returns the response message, if created. Returns <code>null</code> if no response message was created so far.
|
||||
*
|
||||
* @return the response message, or <code>null</code> if none was created
|
||||
* @see #hasResponse()
|
||||
*/
|
||||
SoapMessage getSoapResponse();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Contains the <code>SoapMessageContext</code> interface.
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,11 +2,12 @@ package org.springframework.ws.soap.endpoint;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.endpoint.AbstractEndpointExceptionResolver;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
/**
|
||||
* Simple, SOAP-specific implementation of the <code>EndpointExceptionResolver</code> that stores the exception's
|
||||
@@ -26,12 +27,11 @@ public class SimpleSoapExceptionResolver extends AbstractEndpointExceptionResolv
|
||||
}
|
||||
|
||||
protected boolean resolveExceptionInternal(MessageContext messageContext, Object endpoint, Exception ex) {
|
||||
if (!(messageContext instanceof SoapMessageContext)) {
|
||||
throw new IllegalArgumentException("SimpleSoapExceptionResolver requires a SoapMessageContext");
|
||||
}
|
||||
Assert.isTrue(messageContext.getResponse() instanceof SoapMessage,
|
||||
"SimpleSoapExceptionResolver requires a SoapMessage");
|
||||
SoapMessage response = (SoapMessage) messageContext.getResponse();
|
||||
String faultString = StringUtils.hasLength(ex.getMessage()) ? ex.getMessage() : ex.toString();
|
||||
SoapMessageContext soapContext = (SoapMessageContext) messageContext;
|
||||
SoapBody body = soapContext.getSoapResponse().getSoapBody();
|
||||
SoapBody body = response.getSoapBody();
|
||||
body.addServerOrReceiverFault(faultString, locale);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ package org.springframework.ws.soap.endpoint;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.endpoint.AbstractEndpointExceptionResolver;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.soap.soap11.Soap11Body;
|
||||
|
||||
/**
|
||||
@@ -63,16 +63,15 @@ public class SoapFaultMappingExceptionResolver extends AbstractEndpointException
|
||||
}
|
||||
|
||||
protected boolean resolveExceptionInternal(MessageContext messageContext, Object endpoint, Exception ex) {
|
||||
if (!(messageContext instanceof SoapMessageContext)) {
|
||||
throw new IllegalArgumentException("SoapFaultMappingExceptionResolver requires a SoapMessageContext");
|
||||
}
|
||||
Assert.isTrue(messageContext.getResponse() instanceof SoapMessage,
|
||||
"SimpleSoapExceptionResolver requires a SoapMessage");
|
||||
|
||||
SoapFaultDefinition definition = getFaultDefinition(ex);
|
||||
if (definition == null) {
|
||||
return false;
|
||||
}
|
||||
SoapMessageContext soapContext = (SoapMessageContext) messageContext;
|
||||
SoapMessage response = soapContext.getSoapResponse();
|
||||
SoapBody soapBody = response.getSoapBody();
|
||||
SoapMessage soapResponse = (SoapMessage) messageContext.getResponse();
|
||||
SoapBody soapBody = soapResponse.getSoapBody();
|
||||
|
||||
if (SoapFaultDefinition.SERVER.equals(definition.getFaultCode()) ||
|
||||
SoapFaultDefinition.RECEIVER.equals(definition.getFaultCode())) {
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.endpoint.mapping.AbstractMapBasedEndpointMapping;
|
||||
import org.springframework.ws.soap.SoapEndpointInvocationChain;
|
||||
import org.springframework.ws.soap.SoapEndpointMapping;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportContextHolder;
|
||||
|
||||
/**
|
||||
* Implementation of the <code>EndpointMapping</code> interface to map from <code>SOAPAction</code> headers to endpoint
|
||||
@@ -85,7 +87,10 @@ public class SoapActionEndpointMapping extends AbstractMapBasedEndpointMapping i
|
||||
}
|
||||
|
||||
protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception {
|
||||
Iterator iterator = messageContext.getTransportRequest().getHeaders(SOAP_ACTION_HEADER);
|
||||
TransportContext transportContext = TransportContextHolder.getTransportContext();
|
||||
Assert.notNull(transportContext,
|
||||
"No TransportContext associated with current thread, cannot read SOAPAction header");
|
||||
Iterator iterator = transportContext.getTransportInputStream().getHeaders(SOAP_ACTION_HEADER);
|
||||
String soapAction = "";
|
||||
if (iterator.hasNext()) {
|
||||
soapAction = (String) iterator.next();
|
||||
|
||||
@@ -26,6 +26,7 @@ import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import javax.xml.soap.MimeHeader;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPException;
|
||||
@@ -34,12 +35,12 @@ import javax.xml.soap.SOAPMessage;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.ws.soap.AbstractSoapMessage;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.AttachmentException;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
* SAAJ-specific implementation of the <code>SoapMessage</code> interface. Accessed via the
|
||||
@@ -47,11 +48,10 @@ import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see javax.xml.soap.SOAPMessage
|
||||
* @see SaajSoapMessageContext
|
||||
*/
|
||||
public abstract class SaajSoapMessage extends AbstractSoapMessage {
|
||||
|
||||
private final SOAPMessage saajMessage;
|
||||
private SOAPMessage saajMessage;
|
||||
|
||||
private SoapEnvelope envelope;
|
||||
|
||||
@@ -61,6 +61,7 @@ public abstract class SaajSoapMessage extends AbstractSoapMessage {
|
||||
* @param soapMessage the SAAJ SOAPMessage
|
||||
*/
|
||||
protected SaajSoapMessage(SOAPMessage soapMessage) {
|
||||
Assert.notNull(soapMessage, "soapMessage must not be null");
|
||||
saajMessage = soapMessage;
|
||||
}
|
||||
|
||||
@@ -71,6 +72,14 @@ public abstract class SaajSoapMessage extends AbstractSoapMessage {
|
||||
return saajMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SAAJ <code>SOAPMessage</code> that this <code>SaajSoapMessage</code> is based on.
|
||||
*/
|
||||
public final void setSaajMessage(SOAPMessage soapMessage) {
|
||||
Assert.notNull(soapMessage, "soapMessage must not be null");
|
||||
saajMessage = soapMessage;
|
||||
}
|
||||
|
||||
public final SoapEnvelope getEnvelope() {
|
||||
if (envelope == null) {
|
||||
try {
|
||||
@@ -91,6 +100,21 @@ public abstract class SaajSoapMessage extends AbstractSoapMessage {
|
||||
if (saajMessage.saveRequired()) {
|
||||
saajMessage.saveChanges();
|
||||
}
|
||||
if (outputStream instanceof TransportOutputStream) {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
|
||||
MimeHeaders headers = saajMessage.getMimeHeaders();
|
||||
if (ObjectUtils.isEmpty(headers.getHeader("Content-Type"))) {
|
||||
headers.addHeader("Content-Type", getVersion().getContentType());
|
||||
if (saajMessage.saveRequired()) {
|
||||
saajMessage.saveChanges();
|
||||
}
|
||||
}
|
||||
for (Iterator iterator = headers.getAllHeaders(); iterator.hasNext();) {
|
||||
MimeHeader mimeHeader = (MimeHeader) iterator.next();
|
||||
transportOutputStream.addHeader(mimeHeader.getName(), mimeHeader.getValue());
|
||||
}
|
||||
}
|
||||
saajMessage.writeTo(outputStream);
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
@@ -163,15 +187,6 @@ public abstract class SaajSoapMessage extends AbstractSoapMessage {
|
||||
};
|
||||
}
|
||||
|
||||
public SoapVersion getVersion() {
|
||||
if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
|
||||
return SoapVersion.SOAP_11;
|
||||
}
|
||||
else {
|
||||
return super.getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SAAJ-specific implementation of <code>org.springframework.ws.soap.Attachment</code>
|
||||
*/
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005 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.soap.saaj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.MimeHeader;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapMessageCreationException;
|
||||
import org.springframework.ws.soap.context.AbstractSoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* SAAJ-specific implementation of the <code>SoapMessageContext</code> interface. Created by the
|
||||
* <code>SaajSoapMessageContextFactory</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see SaajSoapMessageContextFactory
|
||||
*/
|
||||
public abstract class SaajSoapMessageContext extends AbstractSoapMessageContext {
|
||||
|
||||
private final MessageFactory messageFactory;
|
||||
|
||||
/**
|
||||
* Creates a new instance based on the given SAAJ request message, and a message factory.
|
||||
*
|
||||
* @param request the request message
|
||||
* @param transportRequest the transport request
|
||||
* @param messageFactory the message factory used for creating a response
|
||||
*/
|
||||
protected SaajSoapMessageContext(SaajSoapMessage request,
|
||||
TransportRequest transportRequest,
|
||||
MessageFactory messageFactory) {
|
||||
super(request, transportRequest);
|
||||
Assert.notNull(messageFactory);
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
public final void sendResponse(TransportResponse transportResponse) throws IOException {
|
||||
if (hasResponse()) {
|
||||
SOAPMessage response = getSaajResponse();
|
||||
try {
|
||||
if (response.saveRequired()) {
|
||||
response.saveChanges();
|
||||
}
|
||||
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
|
||||
MimeHeaders headers = response.getMimeHeaders();
|
||||
if (ObjectUtils.isEmpty(headers.getHeader("Content-Type"))) {
|
||||
headers.addHeader("Content-Type", getSoapResponse().getVersion().getContentType());
|
||||
if (response.saveRequired()) {
|
||||
response.saveChanges();
|
||||
}
|
||||
}
|
||||
for (Iterator iterator = headers.getAllHeaders(); iterator.hasNext();) {
|
||||
MimeHeader mimeHeader = (MimeHeader) iterator.next();
|
||||
transportResponse.addHeader(mimeHeader.getName(), mimeHeader.getValue());
|
||||
}
|
||||
response.writeTo(transportResponse.getOutputStream());
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SaajSoapMessageException("Could not write message to TransportResponse: " + ex.getMessage(),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected SoapMessage createResponseSoapMessage() {
|
||||
try {
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
return createSaajSoapMessage(saajMessage);
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create message: " + ex.toString(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>SaajSoapMessage</code> using the given SAAJ message.
|
||||
*/
|
||||
protected abstract SaajSoapMessage createSaajSoapMessage(SOAPMessage saajMessage);
|
||||
|
||||
/**
|
||||
* Returns the request as a SAAJ SOAP message.
|
||||
*/
|
||||
public final SOAPMessage getSaajRequest() {
|
||||
return ((SaajSoapMessage) getSoapRequest()).getSaajMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response as a SAAJ SOAP message.
|
||||
*/
|
||||
public final SOAPMessage getSaajResponse() {
|
||||
return ((SaajSoapMessage) getSoapResponse()).getSaajMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request to the given SAAJ SOAP message.
|
||||
*/
|
||||
public abstract void setSaajRequest(SOAPMessage request);
|
||||
|
||||
/**
|
||||
* Sets the response to the given SAAJ SOAP message.
|
||||
*/
|
||||
public abstract void setSaajResponse(SOAPMessage response);
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005 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.soap.saaj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.soap.SoapMessageCreationException;
|
||||
import org.springframework.ws.soap.saaj.saaj12.Saaj12SoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* SAAJ-specific implementation of the <code>MessageContextFactory</code> interface. Creates a
|
||||
* <code>SaajSoapMessageContext</code>. This factory will use SAAJ 1.3 when found, or fall back to SAAJ 1.2.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see SaajSoapMessageContext
|
||||
*/
|
||||
public class SaajSoapMessageContextFactory implements MessageContextFactory, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SaajSoapMessageContextFactory.class);
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
private String messageFactoryProtocol;
|
||||
|
||||
public void setMessageFactory(MessageFactory messageFactory) {
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the protocol for the <code>MessageFactory</code>. Only used for SAAJ 1.3+, defaults to
|
||||
* <code>SOAPConstants.DEFAULT_SOAP_PROTOCOL</code> (i.e. SOAP 1.1).
|
||||
*
|
||||
* @see MessageFactory#newInstance(String)
|
||||
* @see SOAPConstants#DEFAULT_SOAP_PROTOCOL
|
||||
* @see SOAPConstants#SOAP_1_1_PROTOCOL
|
||||
* @see SOAPConstants#SOAP_1_2_PROTOCOL
|
||||
* @see SOAPConstants#DYNAMIC_SOAP_PROTOCOL
|
||||
*/
|
||||
public void setSoapProtocol(String messageFactoryProtocol) {
|
||||
this.messageFactoryProtocol = messageFactoryProtocol;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (messageFactory == null) {
|
||||
try {
|
||||
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
|
||||
if (!StringUtils.hasLength(messageFactoryProtocol)) {
|
||||
messageFactoryProtocol = SOAPConstants.DEFAULT_SOAP_PROTOCOL;
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Creating SAAJ 1.3 MessageFactory with " + messageFactoryProtocol);
|
||||
}
|
||||
messageFactory = MessageFactory.newInstance(messageFactoryProtocol);
|
||||
}
|
||||
else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Creating SAAJ 1.2 MessageFactory");
|
||||
}
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("SaajSoapMessageContextFactory requires SAAJ 1.2, which was not" +
|
||||
"found on the classpath");
|
||||
}
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create MessageFactory: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MessageContext createContext(TransportContext transportContext) throws IOException {
|
||||
TransportRequest transportRequest = transportContext.getTransportRequest();
|
||||
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||
for (Iterator headerNames = transportRequest.getHeaderNames(); headerNames.hasNext();) {
|
||||
String headerName = (String) headerNames.next();
|
||||
for (Iterator headerValues = transportRequest.getHeaders(headerName); headerValues.hasNext();) {
|
||||
String headerValue = (String) headerValues.next();
|
||||
StringTokenizer tokenizer = new StringTokenizer(headerValue, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
mimeHeaders.addHeader(headerName, tokenizer.nextToken().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
SOAPMessage requestMessage = messageFactory.createMessage(mimeHeaders, transportRequest.getInputStream());
|
||||
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
|
||||
return new Saaj13SoapMessageContext(requestMessage, transportRequest, messageFactory);
|
||||
}
|
||||
else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
|
||||
return new Saaj12SoapMessageContext(requestMessage, transportRequest, messageFactory);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"SaajSoapMessageContextFactory requires SAAJ 1.2, which was not" + "found on the classpath");
|
||||
}
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create message from TransportRequest: " + ex.getMessage(),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.SoapMessageCreationException;
|
||||
import org.springframework.ws.soap.saaj.saaj12.Saaj12SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
/**
|
||||
* SAAJ-specific implementation of the {@link org.springframework.ws.WebServiceMessageFactory WebServiceMessageFactory}.
|
||||
* This factory will use SAAJ 1.3 when found, or fall back to SAAJ 1.2.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see org.springframework.ws.soap.saaj.SaajSoapMessage
|
||||
*/
|
||||
public class SaajSoapMessageFactory implements WebServiceMessageFactory, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SaajSoapMessageFactory.class);
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
private String messageFactoryProtocol;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
try {
|
||||
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
|
||||
if (!StringUtils.hasLength(messageFactoryProtocol)) {
|
||||
messageFactoryProtocol = SOAPConstants.DEFAULT_SOAP_PROTOCOL;
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Creating SAAJ 1.3 MessageFactory with " + messageFactoryProtocol);
|
||||
}
|
||||
messageFactory = MessageFactory.newInstance(messageFactoryProtocol);
|
||||
}
|
||||
else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Creating SAAJ 1.2 MessageFactory");
|
||||
}
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"SaajSoapMessageContextFactory requires SAAJ 1.2, which was not" + "found on the classpath");
|
||||
}
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create MessageFactory: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage() {
|
||||
try {
|
||||
return createSaajSoapMessage(messageFactory.createMessage());
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create empty message: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||
if (inputStream instanceof TransportInputStream) {
|
||||
TransportInputStream transportInputStream = (TransportInputStream) inputStream;
|
||||
for (Iterator headerNames = transportInputStream.getHeaderNames(); headerNames.hasNext();) {
|
||||
String headerName = (String) headerNames.next();
|
||||
for (Iterator headerValues = transportInputStream.getHeaders(headerName); headerValues.hasNext();) {
|
||||
String headerValue = (String) headerValues.next();
|
||||
StringTokenizer tokenizer = new StringTokenizer(headerValue, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
mimeHeaders.addHeader(headerName, tokenizer.nextToken().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
return createSaajSoapMessage(messageFactory.createMessage(mimeHeaders, inputStream));
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SoapMessageCreationException("Could not create message from InputStream: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private WebServiceMessage createSaajSoapMessage(SOAPMessage requestMessage) {
|
||||
if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
|
||||
return new Saaj13SoapMessage(requestMessage);
|
||||
}
|
||||
else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
|
||||
return new Saaj12SoapMessage(requestMessage);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"SaajSoapMessageContextFactory requires SAAJ 1.2, which was not" + "found on the classpath");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the protocol for the <code>MessageFactory</code>. Only used for SAAJ 1.3+, defaults to
|
||||
* <code>SOAPConstants.DEFAULT_SOAP_PROTOCOL</code> (i.e. SOAP 1.1).
|
||||
*
|
||||
* @see MessageFactory#newInstance(String)
|
||||
* @see javax.xml.soap.SOAPConstants#DEFAULT_SOAP_PROTOCOL
|
||||
* @see javax.xml.soap.SOAPConstants#SOAP_1_1_PROTOCOL
|
||||
* @see javax.xml.soap.SOAPConstants#SOAP_1_2_PROTOCOL
|
||||
* @see javax.xml.soap.SOAPConstants#DYNAMIC_SOAP_PROTOCOL
|
||||
*/
|
||||
public void setSoapProtocol(String messageFactoryProtocol) {
|
||||
this.messageFactoryProtocol = messageFactoryProtocol;
|
||||
}
|
||||
}
|
||||
@@ -20,17 +20,16 @@ import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
|
||||
/**
|
||||
* SAAJ 1.2 specific implementation of the <code>SoapMessage</code> interface. Accessed via the
|
||||
* <code>SaajSoapMessageContext</code>.
|
||||
* SAAJ 1.2 specific implementation of the <code>SoapMessage</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see javax.xml.soap.SOAPMessage
|
||||
* @see org.springframework.ws.soap.saaj.SaajSoapMessageContext
|
||||
*/
|
||||
class Saaj12SoapMessage extends SaajSoapMessage {
|
||||
public class Saaj12SoapMessage extends SaajSoapMessage {
|
||||
|
||||
public Saaj12SoapMessage(SOAPMessage soapMessage) {
|
||||
super(soapMessage);
|
||||
@@ -40,4 +39,7 @@ class Saaj12SoapMessage extends SaajSoapMessage {
|
||||
return new Saaj12SoapEnvelope(saajEnvelope);
|
||||
}
|
||||
|
||||
public SoapVersion getVersion() {
|
||||
return SoapVersion.SOAP_11;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj.saaj12;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* SAAJ 1.2 specific implementation of the <code>SoapMessageContext</code> interface. Created by the
|
||||
* <code>SaajSoapMessageContextFactory</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see org.springframework.ws.soap.saaj.SaajSoapMessageContextFactory
|
||||
*/
|
||||
public class Saaj12SoapMessageContext extends SaajSoapMessageContext {
|
||||
|
||||
/**
|
||||
* Creates a new instance based on the given SAAJ request message, and a message factory.
|
||||
*
|
||||
* @param request the request message
|
||||
* @param transportRequest the transport request
|
||||
* @param messageFactory the message factory used for creating a response
|
||||
*/
|
||||
public Saaj12SoapMessageContext(SOAPMessage request,
|
||||
TransportRequest transportRequest,
|
||||
MessageFactory messageFactory) {
|
||||
super(new Saaj12SoapMessage(request), transportRequest, messageFactory);
|
||||
}
|
||||
|
||||
protected SaajSoapMessage createSaajSoapMessage(SOAPMessage saajMessage) {
|
||||
return new Saaj12SoapMessage(saajMessage);
|
||||
}
|
||||
|
||||
public void setSaajRequest(SOAPMessage request) {
|
||||
setRequest(new Saaj12SoapMessage(request));
|
||||
}
|
||||
|
||||
public void setSaajResponse(SOAPMessage response) {
|
||||
setResponse(new Saaj12SoapMessage(response));
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,19 @@ import javax.xml.soap.SOAPMessage;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
|
||||
class Saaj13SoapMessage extends SaajSoapMessage {
|
||||
/**
|
||||
* SAAJ 1.3 specific implementation of the <code>SoapMessage</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class Saaj13SoapMessage extends SaajSoapMessage {
|
||||
|
||||
/**
|
||||
* Create a new <code>SaajSoapMessage</code> based on the given SAAJ <code>SOAPMessage</code>.
|
||||
*
|
||||
* @param soapMessage the SAAJ SOAPMessage
|
||||
*/
|
||||
protected Saaj13SoapMessage(SOAPMessage soapMessage) {
|
||||
public Saaj13SoapMessage(SOAPMessage soapMessage) {
|
||||
super(soapMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj.saaj13;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* SAAJ 1.3 specific implementation of the <code>SoapMessageContext</code> interface. Created by the
|
||||
* <code>SaajSoapMessageContextFactory</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see org.springframework.ws.soap.saaj.SaajSoapMessageContextFactory
|
||||
*/
|
||||
public class Saaj13SoapMessageContext extends SaajSoapMessageContext {
|
||||
|
||||
/**
|
||||
* Creates a new instance based on the given SAAJ request message, and a message factory.
|
||||
*
|
||||
* @param request the request message
|
||||
* @param transportRequest the transport request
|
||||
* @param messageFactory the message factory used for creating a response
|
||||
*/
|
||||
public Saaj13SoapMessageContext(SOAPMessage request,
|
||||
TransportRequest transportRequest,
|
||||
MessageFactory messageFactory) {
|
||||
super(new Saaj13SoapMessage(request), transportRequest, messageFactory);
|
||||
}
|
||||
|
||||
protected SaajSoapMessage createSaajSoapMessage(SOAPMessage saajMessage) {
|
||||
return new Saaj13SoapMessage(saajMessage);
|
||||
}
|
||||
|
||||
public void setSaajRequest(SOAPMessage request) {
|
||||
setRequest(new Saaj13SoapMessage(request));
|
||||
}
|
||||
|
||||
public void setSaajResponse(SOAPMessage response) {
|
||||
setResponse(new Saaj13SoapMessage(response));
|
||||
}
|
||||
}
|
||||
@@ -150,18 +150,6 @@ public abstract class SaajUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a SAAJ <code>SOAPMessage</code> from the given resource.
|
||||
*
|
||||
* @param resource the resource to read from
|
||||
* @return the loaded SAAJ message
|
||||
* @throws SOAPException if the message cannot be constructed
|
||||
* @throws IOException if the input stream resource cannot be loaded
|
||||
*/
|
||||
public static SOAPMessage loadMessage(Resource resource) throws SOAPException, IOException {
|
||||
return loadMessage(resource, MessageFactory.newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a SAAJ <code>SOAPMessage</code> from the given resource with a given message factory.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
/**
|
||||
* Simple implementation of the <code>TransportContext</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class SimpleTransportContext implements TransportContext {
|
||||
|
||||
private final TransportInputStream transportInputStream;
|
||||
|
||||
private final TransportOutputStream transportOutputStream;
|
||||
|
||||
/**
|
||||
* Creates a new <code>SimpleTransportContext</code> that exposes the given streams.
|
||||
*/
|
||||
public SimpleTransportContext(TransportInputStream transportInputStream,
|
||||
TransportOutputStream transportOutputStream) {
|
||||
this.transportInputStream = transportInputStream;
|
||||
this.transportOutputStream = transportOutputStream;
|
||||
}
|
||||
|
||||
public TransportInputStream getTransportInputStream() {
|
||||
return transportInputStream;
|
||||
}
|
||||
|
||||
public TransportOutputStream getTransportOutputStream() {
|
||||
return transportOutputStream;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
package org.springframework.ws.transport;
|
||||
|
||||
/**
|
||||
* Defines the contract for Web service request that come in via a transport. Exposes headers and the inputstream to
|
||||
* read from.
|
||||
* Strategy interface for determining the current {@link TransportInputStream} and {@link TransportOutputStream}.
|
||||
* <p/>
|
||||
* An instance of this class can be associated with a thread via the {@link TransportContextHolder} class.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface TransportContext {
|
||||
|
||||
TransportRequest getTransportRequest() throws TransportException;
|
||||
|
||||
TransportResponse getTransportResponse() throws TransportException;
|
||||
/**
|
||||
* Returns the current <code>TransportInputStream</code>.
|
||||
*/
|
||||
TransportInputStream getTransportInputStream();
|
||||
|
||||
/**
|
||||
* Returns the current <code>TransportOutputStream</code>.
|
||||
*/
|
||||
TransportOutputStream getTransportOutputStream();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
/**
|
||||
* Simple holder class that associates a <code>TransportContext</code> instance with the current thread. The
|
||||
* <code>TransportContext</code> will be inherited by any child threads spawned by the current thread.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see TransportContext
|
||||
*/
|
||||
public abstract class TransportContextHolder {
|
||||
|
||||
private static final ThreadLocal transportContextHolder = new InheritableThreadLocal();
|
||||
|
||||
/**
|
||||
* Associate the given <code>TransportContext</code> with the current thread.
|
||||
*
|
||||
* @param transportContext the current transport context, or <code>null</code> to reset the thread-bound context
|
||||
*/
|
||||
public static void setTransportContext(TransportContext transportContext) {
|
||||
transportContextHolder.set(transportContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the <code>TransportContext</code> associated with the current thread, if any.
|
||||
*
|
||||
* @return the current transport context, or <code>null</code> if none
|
||||
*/
|
||||
public static TransportContext getTransportContext() {
|
||||
return (TransportContext) transportContextHolder.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A <code>TransportInputStream</code> is an input stream with MIME input headers. It is used to construct {@link
|
||||
* org.springframework.ws.WebServiceMessage WebServiceMessages} from a transport.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see #getHeaderNames()
|
||||
* @see #getHeaders(String)
|
||||
*/
|
||||
public abstract class TransportInputStream extends InputStream {
|
||||
|
||||
protected TransportInputStream() {
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
getInputStream().close();
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return getInputStream().available();
|
||||
}
|
||||
|
||||
public synchronized void mark(int readlimit) {
|
||||
try {
|
||||
getInputStream().mark(readlimit);
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
try {
|
||||
return getInputStream().markSupported();
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int read(byte b[]) throws IOException {
|
||||
return getInputStream().read(b);
|
||||
}
|
||||
|
||||
public int read(byte b[], int off, int len) throws IOException {
|
||||
return getInputStream().read(b, off, len);
|
||||
}
|
||||
|
||||
public synchronized void reset() throws IOException {
|
||||
getInputStream().reset();
|
||||
}
|
||||
|
||||
public long skip(long n) throws IOException {
|
||||
return getInputStream().skip(n);
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return getInputStream().read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input stream to read from.
|
||||
*/
|
||||
protected abstract InputStream getInputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns an iteration over all the header names this request contains. Returns an empty <code>Iterator</code> if
|
||||
* the request has no headers.
|
||||
*/
|
||||
public abstract Iterator getHeaderNames() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns an iteration over all the string values of the specified request header. Returns an empty
|
||||
* <code>Iterator</code> if the request did not include any headers of the specified name.
|
||||
*/
|
||||
public abstract Iterator getHeaders(String name) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* A <code>TransportOutputStream</code> is an output stream with MIME input headers. It is used to write {@link
|
||||
* org.springframework.ws.WebServiceMessage WebServiceMessages} to a transport.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see #addHeader(String,String)
|
||||
*/
|
||||
public abstract class TransportOutputStream extends OutputStream {
|
||||
|
||||
protected TransportOutputStream() {
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
getOutputStream().close();
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
getOutputStream().flush();
|
||||
}
|
||||
|
||||
public void write(byte b[]) throws IOException {
|
||||
getOutputStream().write(b);
|
||||
}
|
||||
|
||||
public void write(byte b[], int off, int len) throws IOException {
|
||||
getOutputStream().write(b, off, len);
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
getOutputStream().write(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a response header with the given name and value. This method can be called multiple times, to allow for
|
||||
* headers with multiple values.
|
||||
*
|
||||
* @param name the name of the header
|
||||
* @param value the value of the header
|
||||
*/
|
||||
public abstract void addHeader(String name, String value) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the output stream to write to.
|
||||
*/
|
||||
protected abstract OutputStream getOutputStream() throws IOException;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Defines the contract for Web service request that come in via a transport. Exposes headers and the inputstream to
|
||||
* read from.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public interface TransportRequest {
|
||||
|
||||
/**
|
||||
* Returns an iteratoion over all the header names this request contains. Returns an empty <code>Iterator</code> if
|
||||
* the request has no headers, this method .
|
||||
*/
|
||||
Iterator getHeaderNames() throws TransportException;
|
||||
|
||||
/**
|
||||
* Returns an iteration over all the string values of the specified request header. Returns an empty
|
||||
* <code>Iterator</code> if the request did not include any headers of the specified name.
|
||||
*/
|
||||
Iterator getHeaders(String name) throws TransportException;
|
||||
|
||||
/**
|
||||
* Returns the contents of the request as a <code>InputStream</code>.
|
||||
*/
|
||||
InputStream getInputStream() throws TransportException, IOException;
|
||||
|
||||
/**
|
||||
* Return a URL handle for this request.
|
||||
*/
|
||||
String getUrl() throws TransportException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2006 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.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.ws.transport.TransportException;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.ws.transport.support.EnumerationIterator;
|
||||
|
||||
/**
|
||||
* HTTP Servlet specific implementation of the <code>TransportInputStream</code> interface. Exposes the
|
||||
* <code>HttpServletRequest</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see #getHttpServletRequest()
|
||||
*/
|
||||
public class HttpServletTransportInputStream extends TransportInputStream {
|
||||
|
||||
private final HttpServletRequest httpServletRequest;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the <code>HttpTransportRequest</code> with the given
|
||||
* <code>HttpServletRequest</code>.
|
||||
*/
|
||||
public HttpServletTransportInputStream(HttpServletRequest httpServletRequest) throws IOException {
|
||||
this.httpServletRequest = httpServletRequest;
|
||||
}
|
||||
|
||||
protected InputStream getInputStream() throws IOException {
|
||||
return httpServletRequest.getInputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped <code>HttpServletRequest</code>.
|
||||
*/
|
||||
public HttpServletRequest getHttpServletRequest() {
|
||||
return httpServletRequest;
|
||||
}
|
||||
|
||||
public Iterator getHeaderNames() throws TransportException {
|
||||
return new EnumerationIterator(httpServletRequest.getHeaderNames());
|
||||
}
|
||||
|
||||
public Iterator getHeaders(String name) throws TransportException {
|
||||
return new EnumerationIterator(httpServletRequest.getHeaders(name));
|
||||
}
|
||||
}
|
||||
@@ -20,38 +20,39 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
* HTTP-specific implementation of the <code>TransportResponse</code> interface. Exposes the
|
||||
* <code>HttpServletResponse</code>
|
||||
* HTTP Servlet specific implementation of the <code>TransportOutputStream</code> interface. Exposes the
|
||||
* <code>HttpServletResponse</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see #getHttpServletResponse()
|
||||
*/
|
||||
public class HttpTransportResponse implements TransportResponse {
|
||||
public class HttpServletTransportOutputStream extends TransportOutputStream {
|
||||
|
||||
private final HttpServletResponse response;
|
||||
private final HttpServletResponse httpServletResponse;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the <code>HttpTransportResponse</code> with the given
|
||||
* <code>HttpServletResponse</code>.
|
||||
*/
|
||||
public HttpTransportResponse(HttpServletResponse response) {
|
||||
this.response = response;
|
||||
public HttpServletTransportOutputStream(HttpServletResponse httpServletResponse) throws IOException {
|
||||
this.httpServletResponse = httpServletResponse;
|
||||
}
|
||||
|
||||
protected OutputStream getOutputStream() throws IOException {
|
||||
return httpServletResponse.getOutputStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped <code>HttpServletResponse</code>.
|
||||
*/
|
||||
public HttpServletResponse getHttpServletResponse() {
|
||||
return response;
|
||||
return httpServletResponse;
|
||||
}
|
||||
|
||||
public void addHeader(String name, String value) {
|
||||
response.addHeader(name, value);
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return response.getOutputStream();
|
||||
httpServletResponse.addHeader(name, value);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.springframework.ws.transport.http;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* HTTP-specific implementation of the <code>TransportContext</code> interface. Exposes the
|
||||
* <code>HttpServletRequest</code> and <code>HttpServletResponse</code>.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class HttpTransportContext implements TransportContext {
|
||||
|
||||
private final HttpTransportRequest transportRequest;
|
||||
|
||||
private final HttpTransportResponse transportResponse;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the <code>HttpTransportContext</code> with the given <code>HttpServletRequest</code>
|
||||
* and <code>HttpServletResponse</code>
|
||||
*/
|
||||
public HttpTransportContext(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
Assert.notNull(httpServletRequest, "No httpServletRequest given");
|
||||
Assert.notNull(httpServletResponse, "No httpServletResponse given");
|
||||
transportRequest = new HttpTransportRequest(httpServletRequest);
|
||||
transportResponse = new HttpTransportResponse(httpServletResponse);
|
||||
}
|
||||
|
||||
public TransportRequest getTransportRequest() {
|
||||
return transportRequest;
|
||||
}
|
||||
|
||||
public TransportResponse getTransportResponse() {
|
||||
return transportResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped <code>HttpServletRequest</code>.
|
||||
*/
|
||||
public HttpServletRequest getHttpServletRequest() {
|
||||
return transportRequest.getHttpServletRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped <code>HttpServletResponse</code>.
|
||||
*/
|
||||
public HttpServletResponse getHttpServletRespo() {
|
||||
return transportResponse.getHttpServletResponse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* HTTP-specific implementation of the <code>TransportRequest</code> interface. Exposes the
|
||||
* <code>HttpServletRequest</code>
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class HttpTransportRequest implements TransportRequest {
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the <code>HttpTransportRequest</code> with the given
|
||||
* <code>HttpServletRequest</code>.
|
||||
*/
|
||||
public HttpTransportRequest(HttpServletRequest request) {
|
||||
Assert.notNull(request, "request is required");
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapped <code>HttpServletRequest</code>.
|
||||
*/
|
||||
public HttpServletRequest getHttpServletRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public Iterator getHeaders(String name) {
|
||||
return new EnumerationIterator(request.getHeaders(name));
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return request.getInputStream();
|
||||
}
|
||||
|
||||
public Iterator getHeaderNames() {
|
||||
return new EnumerationIterator(request.getHeaderNames());
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
StringBuffer url = new StringBuffer(request.getScheme());
|
||||
url.append("://").append(request.getServerName()).append(':').append(request.getServerPort());
|
||||
url.append(request.getRequestURI());
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Private static class that adapts a header enumeration provided by the HttpServletRequest and provides it as an
|
||||
* iterator.
|
||||
*/
|
||||
private static class EnumerationIterator implements Iterator {
|
||||
|
||||
private final Enumeration enumeration;
|
||||
|
||||
public EnumerationIterator(Enumeration enumeration) {
|
||||
this.enumeration = enumeration;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return enumeration.hasMoreElements();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return enumeration.nextElement();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import org.springframework.ws.EndpointAdapter;
|
||||
import org.springframework.ws.EndpointExceptionResolver;
|
||||
import org.springframework.ws.EndpointMapping;
|
||||
import org.springframework.ws.MessageDispatcher;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
/**
|
||||
* Servlet for simplified dispatching of Web service messages. Delegates to a <code>MessageDispatcher</code> and a
|
||||
@@ -75,9 +75,9 @@ public class MessageDispatcherServlet extends FrameworkServlet {
|
||||
public static final String ENDPOINT_MAPPING_BEAN_NAME = "endpointMapping";
|
||||
|
||||
/**
|
||||
* Well-known name for the <code>MessageContextFactory</code> object in the bean factory for this namespace.
|
||||
* Well-known name for the <code>WebServiceMessageFactory</code> object in the bean factory for this namespace.
|
||||
*/
|
||||
public static final String MESSAGE_CONTEXT_FACTORY_BEAN_NAME = "messageContextFactory";
|
||||
public static final String WEB_SERVICE_MESSAGE_FACTORY_BEAN_NAME = "messageFactory";
|
||||
|
||||
/**
|
||||
* Well-known name for the <code>MessageDispatcher</code> object in the bean factory for this namespace.
|
||||
@@ -187,7 +187,7 @@ public class MessageDispatcherServlet extends FrameworkServlet {
|
||||
}
|
||||
|
||||
protected void initFrameworkServlet() throws ServletException, BeansException {
|
||||
initMessageContextFactory();
|
||||
initWebServiceMessageFactory();
|
||||
initMessageDispatcher();
|
||||
}
|
||||
|
||||
@@ -343,29 +343,29 @@ public class MessageDispatcherServlet extends FrameworkServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private void initMessageContextFactory() throws BeansException {
|
||||
MessageContextFactory messageContextFactory;
|
||||
private void initWebServiceMessageFactory() throws BeansException {
|
||||
WebServiceMessageFactory messageFactory;
|
||||
try {
|
||||
messageContextFactory = (MessageContextFactory) getWebApplicationContext()
|
||||
.getBean(MESSAGE_CONTEXT_FACTORY_BEAN_NAME, MessageContextFactory.class);
|
||||
messageFactory = (WebServiceMessageFactory) getWebApplicationContext()
|
||||
.getBean(WEB_SERVICE_MESSAGE_FACTORY_BEAN_NAME, WebServiceMessageFactory.class);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ignored) {
|
||||
messageContextFactory = (MessageContextFactory) getDefaultStrategy(MessageContextFactory.class);
|
||||
messageFactory = (WebServiceMessageFactory) getDefaultStrategy(WebServiceMessageFactory.class);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Unable to locate MessageContextFactory with name '" + MESSAGE_CONTEXT_FACTORY_BEAN_NAME +
|
||||
"': using default [" + messageContextFactory + "]");
|
||||
logger.info("Unable to locate WebServiceMessageFactory with name '" +
|
||||
WEB_SERVICE_MESSAGE_FACTORY_BEAN_NAME + "': using default [" + messageFactory + "]");
|
||||
}
|
||||
if (messageContextFactory instanceof InitializingBean) {
|
||||
if (messageFactory instanceof InitializingBean) {
|
||||
try {
|
||||
((InitializingBean) messageContextFactory).afterPropertiesSet();
|
||||
((InitializingBean) messageFactory).afterPropertiesSet();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new BeanInitializationException(
|
||||
"Could not invoke afterPropertiesSet() on messageContextFactory", ex);
|
||||
throw new BeanInitializationException("Could not invoke afterPropertiesSet() on message factory",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
handlerAdapter.setMessageContextFactory(messageContextFactory);
|
||||
handlerAdapter.setMessageFactory(messageFactory);
|
||||
}
|
||||
|
||||
private void initMessageDispatcher() {
|
||||
|
||||
@@ -28,33 +28,38 @@ import org.springframework.web.servlet.HandlerAdapter;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.ws.NoEndpointFoundException;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.endpoint.MessageEndpoint;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.transport.SimpleTransportContext;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportContextHolder;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
* Adapter to use the <code>MessageEndpoint</code> interface with the generic <code>DispatcherServlet</code>. Requires a
|
||||
* <code>MessageContextFactory</code>, which is used to convert the incoming <code>HttpServletRequest</code> into a
|
||||
* <code>MessageContext</code>, and passes that context to the mapped <code>MessageEndpoint</code>. If a response is
|
||||
* created, that is sent via the <code>HttpServletResponse</code>.
|
||||
* {@link WebServiceMessageFactory}, which is used to convert the incoming <code>HttpServletRequest</code> into a {@link
|
||||
* WebServiceMessage}, and passes that context to the mapped <code>MessageEndpoint</code>. If a response is created,
|
||||
* that is sent via the <code>HttpServletResponse</code>.
|
||||
* <p/>
|
||||
* Note that the <code>MessageDispatcher</code> implements the <code>MessageEndpoint</code> interface, enabling this
|
||||
* adapter to function as a gateway to further message handling logic.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see org.springframework.ws.endpoint.MessageEndpoint
|
||||
* @see MessageContextFactory
|
||||
* @see org.springframework.ws.MessageDispatcher
|
||||
*/
|
||||
public class MessageEndpointHandlerAdapter implements HandlerAdapter, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MessageEndpointHandlerAdapter.class);
|
||||
|
||||
private MessageContextFactory messageContextFactory;
|
||||
private WebServiceMessageFactory messageFactory;
|
||||
|
||||
public void setMessageContextFactory(MessageContextFactory messageContextFactory) {
|
||||
this.messageContextFactory = messageContextFactory;
|
||||
public void setMessageFactory(WebServiceMessageFactory messageFactory) {
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
public long getLastModified(HttpServletRequest request, Object handler) {
|
||||
@@ -78,34 +83,43 @@ public class MessageEndpointHandlerAdapter implements HandlerAdapter, Initializi
|
||||
}
|
||||
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(messageContextFactory, "messageContextFactory is required");
|
||||
logger.info("Using message context factory " + messageContextFactory);
|
||||
Assert.notNull(messageFactory, "messageFactory is required");
|
||||
logger.info("Using message factory [" + messageFactory + "]");
|
||||
}
|
||||
|
||||
private void handlePost(HttpServletRequest httpServletRequest,
|
||||
MessageEndpoint endpoint,
|
||||
HttpServletResponse httpServletResponse) throws Exception {
|
||||
HttpTransportContext transportContext = new HttpTransportContext(httpServletRequest, httpServletResponse);
|
||||
MessageContext messageContext = messageContextFactory.createContext(transportContext);
|
||||
TransportInputStream tis = new HttpServletTransportInputStream(httpServletRequest);
|
||||
TransportOutputStream tos = new HttpServletTransportOutputStream(httpServletResponse);
|
||||
|
||||
TransportContext previousTransportContext = TransportContextHolder.getTransportContext();
|
||||
TransportContextHolder.setTransportContext(new SimpleTransportContext(tis, tos));
|
||||
|
||||
try {
|
||||
WebServiceMessage messageRequest = messageFactory.createWebServiceMessage(tis);
|
||||
MessageContext messageContext = new DefaultMessageContext(messageRequest, messageFactory);
|
||||
endpoint.invoke(messageContext);
|
||||
if (!messageContext.hasResponse()) {
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
}
|
||||
else {
|
||||
WebServiceMessage webServiceResponse = messageContext.getResponse();
|
||||
if (webServiceResponse instanceof SoapMessage &&
|
||||
((SoapMessage) webServiceResponse).getSoapBody().hasFault()) {
|
||||
WebServiceMessage messageResponse = messageContext.getResponse();
|
||||
if (messageResponse instanceof SoapMessage &&
|
||||
((SoapMessage) messageResponse).getSoapBody().hasFault()) {
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
else {
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
messageContext.sendResponse(new HttpTransportResponse(httpServletResponse));
|
||||
messageResponse.writeTo(tos);
|
||||
}
|
||||
}
|
||||
catch (NoEndpointFoundException ex) {
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
finally {
|
||||
TransportContextHolder.setTransportContext(previousTransportContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
org.springframework.ws.MessageDispatcher=org.springframework.ws.soap.SoapMessageDispatcher
|
||||
|
||||
org.springframework.ws.context.MessageContextFactory=org.springframework.ws.soap.saaj.SaajSoapMessageContextFactory
|
||||
org.springframework.ws.WebServiceMessageFactory=org.springframework.ws.soap.saaj.SaajSoapMessageFactory
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public abstract class AbstractWebServiceMessageFactoryTestCase extends TestCase {
|
||||
|
||||
protected WebServiceMessageFactory messageFactory;
|
||||
|
||||
protected final void setUp() throws Exception {
|
||||
messageFactory = createMessageFactory();
|
||||
}
|
||||
|
||||
public void testCreateEmptyMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertNotNull("WebServiceMessage is null", message);
|
||||
}
|
||||
|
||||
protected abstract WebServiceMessageFactory createMessageFactory() throws Exception;
|
||||
}
|
||||
@@ -20,18 +20,24 @@ import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
|
||||
public class MessageDispatcherTest extends TestCase {
|
||||
|
||||
private MessageDispatcher dispatcher;
|
||||
|
||||
private MockMessageContext messageContext;
|
||||
private MessageContext messageContext;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dispatcher = new MessageDispatcher();
|
||||
messageContext = new MockMessageContext();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
messageContext = new DefaultMessageContext(new MockWebServiceMessage(), factoryMock);
|
||||
}
|
||||
|
||||
public void testGetEndpoint() throws Exception {
|
||||
@@ -44,8 +50,10 @@ public class MessageDispatcherTest extends TestCase {
|
||||
mappingControl.expectAndReturn(mappingMock.getEndpoint(messageContext), chain);
|
||||
|
||||
mappingControl.replay();
|
||||
factoryControl.replay();
|
||||
EndpointInvocationChain result = dispatcher.getEndpoint(messageContext);
|
||||
mappingControl.verify();
|
||||
factoryControl.verify();
|
||||
assertEquals("getEndpoint returns invalid EndpointInvocationChain", chain, result);
|
||||
}
|
||||
|
||||
@@ -57,8 +65,10 @@ public class MessageDispatcherTest extends TestCase {
|
||||
Object endpoint = new Object();
|
||||
adapterControl.expectAndReturn(adapterMock.supports(endpoint), true);
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
EndpointAdapter result = dispatcher.getEndpointAdapter(endpoint);
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
assertEquals("getEnpointAdapter returns invalid EndpointAdapter", adapterMock, result);
|
||||
}
|
||||
|
||||
@@ -70,6 +80,7 @@ public class MessageDispatcherTest extends TestCase {
|
||||
Object endpoint = new Object();
|
||||
adapterControl.expectAndReturn(adapterMock.supports(endpoint), false);
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
try {
|
||||
dispatcher.getEndpointAdapter(endpoint);
|
||||
fail("getEndpointAdapter does not throw IllegalStateException for unsupported endpoint");
|
||||
@@ -78,6 +89,7 @@ public class MessageDispatcherTest extends TestCase {
|
||||
// Expected
|
||||
}
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessEndpointExceptionReturnsResponse() throws Exception {
|
||||
@@ -98,9 +110,12 @@ public class MessageDispatcherTest extends TestCase {
|
||||
|
||||
};
|
||||
dispatcher.setEndpointExceptionResolvers(Collections.singletonList(resolver));
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), new MockWebServiceMessage());
|
||||
factoryControl.replay();
|
||||
|
||||
dispatcher.processEndpointException(messageContext, endpoint, ex);
|
||||
assertNotNull("processEndpointException sets no response", messageContext.getResponse());
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessUnsupportedEndpointException() throws Exception {
|
||||
@@ -149,10 +164,12 @@ public class MessageDispatcherTest extends TestCase {
|
||||
new EndpointInvocationChain(endpoint, new EndpointInterceptor[]{interceptorMock1, interceptorMock2});
|
||||
|
||||
mappingControl.expectAndReturn(mappingMock.getEndpoint(messageContext), chain);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), new MockWebServiceMessage());
|
||||
|
||||
mappingControl.replay();
|
||||
interceptorControl.replay();
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
// response required for interceptor invocation
|
||||
messageContext.getResponse();
|
||||
dispatcher.dispatch(messageContext);
|
||||
@@ -160,6 +177,7 @@ public class MessageDispatcherTest extends TestCase {
|
||||
mappingControl.verify();
|
||||
interceptorControl.verify();
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testFlowNoResponse() throws Exception {
|
||||
@@ -189,12 +207,14 @@ public class MessageDispatcherTest extends TestCase {
|
||||
mappingControl.replay();
|
||||
interceptorControl.replay();
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
|
||||
dispatcher.dispatch(messageContext);
|
||||
|
||||
mappingControl.verify();
|
||||
interceptorControl.verify();
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testInterceptedRequestFlow() throws Exception {
|
||||
@@ -218,10 +238,12 @@ public class MessageDispatcherTest extends TestCase {
|
||||
new EndpointInvocationChain(endpoint, new EndpointInterceptor[]{interceptorMock1, interceptorMock2});
|
||||
|
||||
mappingControl.expectAndReturn(mappingMock.getEndpoint(messageContext), chain);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), new MockWebServiceMessage());
|
||||
|
||||
mappingControl.replay();
|
||||
interceptorControl.replay();
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
|
||||
// response required for interceptor invocation
|
||||
messageContext.getResponse();
|
||||
@@ -231,6 +253,7 @@ public class MessageDispatcherTest extends TestCase {
|
||||
mappingControl.verify();
|
||||
interceptorControl.verify();
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testInterceptedResponseFlow() throws Exception {
|
||||
@@ -255,10 +278,12 @@ public class MessageDispatcherTest extends TestCase {
|
||||
new EndpointInvocationChain(endpoint, new EndpointInterceptor[]{interceptorMock1, interceptorMock2});
|
||||
|
||||
mappingControl.expectAndReturn(mappingMock.getEndpoint(messageContext), chain);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), new MockWebServiceMessage());
|
||||
|
||||
mappingControl.replay();
|
||||
interceptorControl.replay();
|
||||
adapterControl.replay();
|
||||
factoryControl.replay();
|
||||
// response required for interceptor invocation
|
||||
messageContext.getResponse();
|
||||
|
||||
@@ -267,6 +292,7 @@ public class MessageDispatcherTest extends TestCase {
|
||||
mappingControl.verify();
|
||||
interceptorControl.verify();
|
||||
adapterControl.verify();
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.mock;
|
||||
package org.springframework.ws;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -34,7 +34,6 @@ import javax.xml.transform.stream.StreamResult;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
public class MockWebServiceMessageFactory implements WebServiceMessageFactory {
|
||||
|
||||
public WebServiceMessage createWebServiceMessage() {
|
||||
return new MockWebServiceMessage();
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
try {
|
||||
return new MockWebServiceMessage(new StreamSource(inputStream));
|
||||
}
|
||||
catch (TransformerException ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2006 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.context;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
public class DefaultMessageContextTest extends TestCase {
|
||||
|
||||
private DefaultMessageContext context;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
private WebServiceMessage request;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, factoryMock);
|
||||
}
|
||||
|
||||
public void testRequest() throws Exception {
|
||||
assertEquals("Invalid request returned", request, context.getRequest());
|
||||
}
|
||||
|
||||
public void testResponse() throws Exception {
|
||||
WebServiceMessage response = new MockWebServiceMessage();
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), response);
|
||||
factoryControl.replay();
|
||||
|
||||
WebServiceMessage result = context.getResponse();
|
||||
assertEquals("Invalid response returned", response, result);
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testProperties() throws Exception {
|
||||
assertEquals("Invalid property names returned", 0, context.getPropertyNames().length);
|
||||
String name = "name";
|
||||
assertFalse("Property set", context.containsProperty(name));
|
||||
String value = "value";
|
||||
context.setProperty(name, value);
|
||||
assertTrue("Property not set", context.containsProperty(name));
|
||||
assertEquals("Invalid property names returned", Arrays.asList(new String[]{name}),
|
||||
Arrays.asList(context.getPropertyNames()));
|
||||
assertEquals("Invalid property value returned", value, context.getProperty(name));
|
||||
context.removeProperty(name);
|
||||
assertFalse("Property set", context.containsProperty(name));
|
||||
assertEquals("Invalid property names returned", 0, context.getPropertyNames().length);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,10 @@ package org.springframework.ws.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public abstract class AbstractMessageEndpointTestCase extends AbstractEndpointTestCase {
|
||||
@@ -33,13 +35,16 @@ public abstract class AbstractMessageEndpointTestCase extends AbstractEndpointTe
|
||||
public void testNoResponse() throws Exception {
|
||||
endpoint = createNoResponseEndpoint();
|
||||
StringSource requestSource = new StringSource(REQUEST);
|
||||
MockMessageContext context = new MockMessageContext(new MockWebServiceMessage(requestSource));
|
||||
|
||||
MessageContext context =
|
||||
new DefaultMessageContext(new MockWebServiceMessage(requestSource), new MockWebServiceMessageFactory());
|
||||
endpoint.invoke(context);
|
||||
assertFalse("Response message created", context.hasResponse());
|
||||
}
|
||||
|
||||
protected final void testSource(Source requestSource) throws Exception {
|
||||
MockMessageContext context = new MockMessageContext(new MockWebServiceMessage(requestSource));
|
||||
MessageContext context =
|
||||
new DefaultMessageContext(new MockWebServiceMessage(requestSource), new MockWebServiceMessageFactory());
|
||||
endpoint.invoke(context);
|
||||
assertTrue("No response message created", context.hasResponse());
|
||||
assertXMLEqual(RESPONSE, ((MockWebServiceMessage) context.getResponse()).getPayloadAsString());
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ws.endpoint;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
@@ -28,19 +27,36 @@ import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class MarshallingPayloadEndpointTest extends XMLTestCase {
|
||||
|
||||
public void testInvoke() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
private Transformer transformer;
|
||||
|
||||
private MessageContext context;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
|
||||
context = new DefaultMessageContext(request, factoryMock);
|
||||
|
||||
}
|
||||
|
||||
public void testInvoke() throws Exception {
|
||||
Unmarshaller unmarshaller = new Unmarshaller() {
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
try {
|
||||
@@ -76,17 +92,18 @@ public class MarshallingPayloadEndpointTest extends XMLTestCase {
|
||||
endpoint.setUnmarshaller(unmarshaller);
|
||||
endpoint.afterPropertiesSet();
|
||||
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), new MockWebServiceMessage());
|
||||
factoryControl.replay();
|
||||
|
||||
endpoint.invoke(context);
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
assertNotNull("Invalid result", response);
|
||||
assertXMLEqual("Invalid response", "<result/>", response.getPayloadAsString());
|
||||
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
public void testInvokeNullResponse() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
|
||||
Unmarshaller unmarshaller = new Unmarshaller() {
|
||||
public Object unmarshal(Source source) throws XmlMappingException {
|
||||
try {
|
||||
@@ -115,9 +132,10 @@ public class MarshallingPayloadEndpointTest extends XMLTestCase {
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(unmarshaller);
|
||||
endpoint.afterPropertiesSet();
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
factoryControl.replay();
|
||||
endpoint.invoke(context);
|
||||
assertFalse("Response created", context.hasResponse());
|
||||
factoryControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ package org.springframework.ws.endpoint;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class MessageEndpointAdapterTest extends TestCase {
|
||||
|
||||
@@ -40,7 +41,7 @@ public class MessageEndpointAdapterTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testInvoke() throws Exception {
|
||||
MockMessageContext context = new MockMessageContext();
|
||||
MessageContext context = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
|
||||
endpointMock.invoke(context);
|
||||
endpointControl.replay();
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ws.endpoint;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
@@ -27,10 +26,10 @@ import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
|
||||
public class PayloadEndpointAdapterTest extends XMLTestCase {
|
||||
|
||||
@@ -62,7 +61,7 @@ public class PayloadEndpointAdapterTest extends XMLTestCase {
|
||||
}
|
||||
};
|
||||
endpoint.invoke(request.getPayloadSource());
|
||||
MessageContext messageContext = new MockMessageContext(request);
|
||||
MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
adapter.invoke(messageContext, endpoint);
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse();
|
||||
assertNotNull("No response created", response);
|
||||
@@ -70,7 +69,7 @@ public class PayloadEndpointAdapterTest extends XMLTestCase {
|
||||
}
|
||||
|
||||
public void testInvokeNoResponse() throws Exception {
|
||||
MessageContext messageContext = new MockMessageContext();
|
||||
MessageContext messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
endpointMock.invoke(messageContext.getRequest().getPayloadSource());
|
||||
endpointControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
endpointControl.setReturnValue(null);
|
||||
|
||||
@@ -25,9 +25,10 @@ import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessage;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageContext;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
@@ -75,7 +76,9 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
AxiomSoapMessageContext context = new AxiomSoapMessageContext(request, new MockTransportRequest());
|
||||
AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
|
||||
soapMessageFactory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(request, soapMessageFactory);
|
||||
|
||||
MessageEndpoint endpoint = createResponseEndpoint();
|
||||
endpoint.invoke(context);
|
||||
@@ -90,7 +93,9 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
AxiomSoapMessageContext context = new AxiomSoapMessageContext(request, new MockTransportRequest());
|
||||
AxiomSoapMessageFactory soapMessageFactory = new AxiomSoapMessageFactory();
|
||||
soapMessageFactory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(request, soapMessageFactory);
|
||||
|
||||
MessageEndpoint endpoint = createNoResponseEndpoint();
|
||||
endpoint.invoke(context);
|
||||
|
||||
@@ -22,8 +22,10 @@ import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class PayloadLoggingInterceptorTest extends TestCase {
|
||||
|
||||
@@ -31,7 +33,7 @@ public class PayloadLoggingInterceptorTest extends TestCase {
|
||||
|
||||
private CountingAppender appender;
|
||||
|
||||
private MockMessageContext messageContext;
|
||||
private MessageContext messageContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
interceptor = new PayloadLoggingInterceptor();
|
||||
@@ -39,7 +41,7 @@ public class PayloadLoggingInterceptorTest extends TestCase {
|
||||
BasicConfigurator.configure(appender);
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
messageContext = new MockMessageContext(request);
|
||||
messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
appender.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
@@ -55,7 +57,7 @@ public class PayloadTransformingInterceptorTest extends XMLTestCase {
|
||||
interceptor.setRequestXslt(xslt);
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage(input);
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid interceptor result", result);
|
||||
@@ -68,7 +70,7 @@ public class PayloadTransformingInterceptorTest extends XMLTestCase {
|
||||
interceptor.setResponseXslt(xslt);
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage(input);
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid interceptor result", result);
|
||||
@@ -81,7 +83,7 @@ public class PayloadTransformingInterceptorTest extends XMLTestCase {
|
||||
interceptor.setResponseXslt(xslt);
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage(input);
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(input);
|
||||
|
||||
@@ -96,7 +98,7 @@ public class PayloadTransformingInterceptorTest extends XMLTestCase {
|
||||
interceptor.setRequestXslt(xslt);
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage(input);
|
||||
MockMessageContext context = new MockMessageContext(request);
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(input);
|
||||
|
||||
|
||||
@@ -30,13 +30,14 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
@@ -45,9 +46,9 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
|
||||
private PayloadValidatingInterceptor interceptor;
|
||||
|
||||
private MockWebServiceMessage request;
|
||||
private MessageContext context;
|
||||
|
||||
private MockMessageContext messageContext;
|
||||
private SaajSoapMessageFactory factory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
interceptor = new PayloadValidatingInterceptor();
|
||||
@@ -55,8 +56,10 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
interceptor.setValidateRequest(true);
|
||||
interceptor.setValidateResponse(true);
|
||||
interceptor.afterPropertiesSet();
|
||||
request = new MockWebServiceMessage();
|
||||
messageContext = new MockMessageContext(request);
|
||||
|
||||
factory = new SaajSoapMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
context = new DefaultMessageContext(factory);
|
||||
}
|
||||
|
||||
public void testHandleInvalidRequestSoap11() throws Exception {
|
||||
@@ -65,13 +68,12 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
|
||||
transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(invalidMessage, new MockTransportRequest(), messageFactory);
|
||||
context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
@@ -87,13 +89,14 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
|
||||
transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(invalidMessage, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
@@ -115,13 +118,12 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml");
|
||||
transformer.transform(new StreamSource(inputStream), new DOMResult(invalidMessage.getSOAPBody()));
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(invalidMessage, new MockTransportRequest(), messageFactory);
|
||||
context = new DefaultMessageContext(new Saaj13SoapMessage(invalidMessage), factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
@@ -132,29 +134,37 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testHandlerInvalidRequest() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
request.setPayload(new ClassPathResource("invalidMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleRequest(messageContext, null);
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
public void testHandleValidRequest() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
request.setPayload(new ClassPathResource("validMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleRequest(messageContext, null);
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", messageContext.hasResponse());
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
|
||||
public void testHandleInvalidResponse() throws Exception {
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource("invalidMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleResponse(messageContext, null);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
public void testHandleValidResponse() throws Exception {
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource("validMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleResponse(messageContext, null);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@@ -169,11 +179,9 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage saajMessage =
|
||||
SaajUtils.loadMessage(new ClassPathResource("validSoapMessage.xml", getClass()), messageFactory);
|
||||
SaajSoapMessageContext soapContext =
|
||||
new Saaj13SoapMessageContext(saajMessage, new MockTransportRequest(), messageFactory);
|
||||
boolean result = interceptor.handleRequest(soapContext, null);
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", soapContext.hasResponse());
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
finally {
|
||||
// Reset the property
|
||||
@@ -196,8 +204,10 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()),
|
||||
new ClassPathResource("sizeSchema.xsd", getClass())});
|
||||
interceptor.afterPropertiesSet();
|
||||
request.setPayload(new ClassPathResource("invalidMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleRequest(messageContext, null);
|
||||
MockWebServiceMessage request =
|
||||
new MockWebServiceMessage(new ClassPathResource("invalidMessage.xml", getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@@ -205,19 +215,24 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()),
|
||||
new ClassPathResource("sizeSchema.xsd", getClass())});
|
||||
interceptor.afterPropertiesSet();
|
||||
request.setPayload(new ClassPathResource("validMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleRequest(messageContext, null);
|
||||
MockWebServiceMessage request =
|
||||
new MockWebServiceMessage(new ClassPathResource("validMessage.xml", getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", messageContext.hasResponse());
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
|
||||
public void testHandleInvalidResponseMultipleSchemas() throws Exception {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()),
|
||||
new ClassPathResource("sizeSchema.xsd", getClass())});
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource("invalidMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleResponse(messageContext, null);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@@ -225,9 +240,11 @@ public class PayloadValidatingInterceptorTest extends TestCase {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()),
|
||||
new ClassPathResource("sizeSchema.xsd", getClass())});
|
||||
interceptor.afterPropertiesSet();
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse();
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource("validMessage.xml", getClass()));
|
||||
boolean result = interceptor.handleResponse(messageContext, null);
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
}
|
||||
}
|
||||
@@ -17,98 +17,111 @@
|
||||
package org.springframework.ws.endpoint.mapping;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.ws.EndpointInterceptor;
|
||||
import org.springframework.ws.EndpointInvocationChain;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
|
||||
public class EndpointMappingTest extends TestCase {
|
||||
|
||||
private MessageContext mockContext;
|
||||
|
||||
private MockControl contextControl;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
contextControl = MockControl.createControl(MessageContext.class);
|
||||
mockContext = (MessageContext) contextControl.getMock();
|
||||
}
|
||||
|
||||
public void testDefaultEndpoint() throws Exception {
|
||||
final MockMessageContext context = new MockMessageContext();
|
||||
Object defaultEndpoint = new Object();
|
||||
AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
|
||||
protected Object getEndpointInternal(MessageContext givenRequest) throws Exception {
|
||||
assertEquals("Invalid request passed", context, givenRequest);
|
||||
assertEquals("Invalid request passed", mockContext, givenRequest);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
mapping.setDefaultEndpoint(defaultEndpoint);
|
||||
contextControl.replay();
|
||||
|
||||
EndpointInvocationChain result = mapping.getEndpoint(context);
|
||||
EndpointInvocationChain result = mapping.getEndpoint(mockContext);
|
||||
assertNotNull("No EndpointInvocatioChain returned", result);
|
||||
assertEquals("Default Endpoint not returned", defaultEndpoint, result.getEndpoint());
|
||||
contextControl.verify();
|
||||
}
|
||||
|
||||
public void testEndpoint() throws Exception {
|
||||
final MockMessageContext context = new MockMessageContext();
|
||||
final Object endpoint = new Object();
|
||||
AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
|
||||
protected Object getEndpointInternal(MessageContext givenRequest) throws Exception {
|
||||
assertEquals("Invalid request passed", context, givenRequest);
|
||||
assertEquals("Invalid request passed", mockContext, givenRequest);
|
||||
return endpoint;
|
||||
}
|
||||
};
|
||||
contextControl.replay();
|
||||
|
||||
EndpointInvocationChain result = mapping.getEndpoint(context);
|
||||
EndpointInvocationChain result = mapping.getEndpoint(mockContext);
|
||||
assertNotNull("No EndpointInvocatioChain returned", result);
|
||||
assertEquals("Unexpected Endpoint returned", endpoint, result.getEndpoint());
|
||||
contextControl.verify();
|
||||
}
|
||||
|
||||
public void testEndpointInterceptors() throws Exception {
|
||||
final MockMessageContext context = new MockMessageContext();
|
||||
final Object endpoint = new Object();
|
||||
EndpointInterceptor interceptor = new EndpointInterceptorAdapter();
|
||||
AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
|
||||
protected Object getEndpointInternal(MessageContext givenRequest) throws Exception {
|
||||
assertEquals("Invalid request passed", context, givenRequest);
|
||||
assertEquals("Invalid request passed", mockContext, givenRequest);
|
||||
return endpoint;
|
||||
}
|
||||
};
|
||||
contextControl.replay();
|
||||
mapping.setInterceptors(new EndpointInterceptor[]{interceptor});
|
||||
EndpointInvocationChain result = mapping.getEndpoint(context);
|
||||
EndpointInvocationChain result = mapping.getEndpoint(mockContext);
|
||||
assertEquals("Unexpected amount of EndpointInterceptors returned", 1, result.getInterceptors().length);
|
||||
assertEquals("Unexpected EndpointInterceptor returned", interceptor, result.getInterceptors()[0]);
|
||||
contextControl.verify();
|
||||
}
|
||||
|
||||
public void testEndpointBeanName() throws Exception {
|
||||
final MockMessageContext context = new MockMessageContext();
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("endpoint", Object.class);
|
||||
|
||||
AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
|
||||
|
||||
protected Object getEndpointInternal(MessageContext message) throws Exception {
|
||||
assertEquals("Invalid request", context, message);
|
||||
assertEquals("Invalid request", mockContext, message);
|
||||
return "endpoint";
|
||||
}
|
||||
};
|
||||
mapping.setApplicationContext(applicationContext);
|
||||
contextControl.replay();
|
||||
|
||||
EndpointInvocationChain result = mapping.getEndpoint(context);
|
||||
EndpointInvocationChain result = mapping.getEndpoint(mockContext);
|
||||
assertNotNull("No endpoint returned", result);
|
||||
contextControl.verify();
|
||||
}
|
||||
|
||||
public void testEndpointInvalidBeanName() throws Exception {
|
||||
final MockMessageContext context = new MockMessageContext();
|
||||
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("endpoint", Object.class);
|
||||
|
||||
AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
|
||||
|
||||
protected Object getEndpointInternal(MessageContext message) throws Exception {
|
||||
assertEquals("Invalid request", context, message);
|
||||
assertEquals("Invalid request", mockContext, message);
|
||||
return "noSuchBean";
|
||||
}
|
||||
};
|
||||
mapping.setApplicationContext(applicationContext);
|
||||
contextControl.replay();
|
||||
|
||||
EndpointInvocationChain result = mapping.getEndpoint(context);
|
||||
EndpointInvocationChain result = mapping.getEndpoint(mockContext);
|
||||
|
||||
assertNull("No endpoint returned", result);
|
||||
contextControl.verify();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ package org.springframework.ws.endpoint.mapping;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class PayloadRootQNameEndpointMappingTest extends TestCase {
|
||||
|
||||
@@ -31,7 +34,8 @@ public class PayloadRootQNameEndpointMappingTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testResolveQNames() throws Exception {
|
||||
MockMessageContext context = new MockMessageContext("<root/>");
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<root/>");
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
QName qName = mapping.resolveQName(context);
|
||||
assertNotNull("mapping returns null", qName);
|
||||
@@ -39,7 +43,8 @@ public class PayloadRootQNameEndpointMappingTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetQNameNameNamespace() throws Exception {
|
||||
MockMessageContext context = new MockMessageContext("<prefix:localname xmlns:prefix=\"namespace\"/>");
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<prefix:localname xmlns:prefix=\"namespace\"/>");
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
QName qName = mapping.resolveQName(context);
|
||||
assertNotNull("mapping returns null", qName);
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.AbstractMessageContext;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* Mock implementation of the <code>MessageContext</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MockMessageContext extends AbstractMessageContext {
|
||||
|
||||
private TransportResponse transportResponse;
|
||||
|
||||
public MockMessageContext() {
|
||||
super(new MockWebServiceMessage(), new MockTransportRequest());
|
||||
}
|
||||
|
||||
public MockMessageContext(MockWebServiceMessage request) {
|
||||
super(request, new MockTransportRequest());
|
||||
}
|
||||
|
||||
public MockMessageContext(MockWebServiceMessage request, TransportContext transportContext) {
|
||||
super(request, transportContext.getTransportRequest());
|
||||
transportResponse = transportContext.getTransportResponse();
|
||||
}
|
||||
|
||||
public MockMessageContext(String content) {
|
||||
super(new MockWebServiceMessage(content), new MockTransportRequest());
|
||||
}
|
||||
|
||||
protected WebServiceMessage createResponseMessage() {
|
||||
return new MockWebServiceMessage();
|
||||
}
|
||||
|
||||
public void sendResponse(TransportResponse transportResponse) throws IOException {
|
||||
getResponse().writeTo(this.transportResponse.getOutputStream());
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.mock;
|
||||
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* Mock implementation of the <code>TransportContext</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MockTransportContext implements TransportContext {
|
||||
|
||||
private MockTransportRequest request;
|
||||
|
||||
private MockTransportResponse response;
|
||||
|
||||
public MockTransportContext() {
|
||||
request = new MockTransportRequest();
|
||||
response = new MockTransportResponse();
|
||||
}
|
||||
|
||||
public MockTransportContext(MockTransportRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public MockTransportContext(MockTransportRequest request, MockTransportResponse response) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public TransportRequest getTransportRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public TransportResponse getTransportResponse() {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.mock;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
/**
|
||||
* Mock implementation of the <code>TransportRequest</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MockTransportRequest implements TransportRequest {
|
||||
|
||||
private byte[] contents;
|
||||
|
||||
private Properties headers;
|
||||
|
||||
private String url;
|
||||
|
||||
public MockTransportRequest() {
|
||||
headers = new Properties();
|
||||
contents = new byte[0];
|
||||
}
|
||||
|
||||
public MockTransportRequest(Properties headers, byte[] contents) {
|
||||
Assert.notNull(headers, "headers must not be null");
|
||||
Assert.notNull(contents, "contents must not be null");
|
||||
this.headers = headers;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public MockTransportRequest(byte[] contents) {
|
||||
Assert.notNull(contents, "contents must not be null");
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(contents);
|
||||
}
|
||||
|
||||
public Iterator getHeaderNames() {
|
||||
return headers.keySet().iterator();
|
||||
}
|
||||
|
||||
public Iterator getHeaders(String name) {
|
||||
String value = headers.getProperty(name);
|
||||
return value != null ? Collections.singletonList(value).iterator() : Collections.EMPTY_LIST.iterator();
|
||||
}
|
||||
|
||||
public void addHeader(String name, String value) {
|
||||
headers.setProperty(name, value);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.mock;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.ws.transport.TransportResponse;
|
||||
|
||||
/**
|
||||
* Mock implementation of the <code>TransportResponse</code> interface.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class MockTransportResponse implements TransportResponse {
|
||||
|
||||
private Properties headers = new Properties();
|
||||
|
||||
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
public void addHeader(String name, String value) {
|
||||
String currentValue = headers.getProperty(name);
|
||||
if (currentValue != null) {
|
||||
value = currentValue + "," + value;
|
||||
}
|
||||
headers.setProperty(name, value);
|
||||
}
|
||||
|
||||
public Properties getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getContents() {
|
||||
try {
|
||||
return new String(outputStream.toByteArray(), "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return outputStream;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.pox.dom;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
|
||||
public class DomPoxMessageContextFactoryTest extends TestCase {
|
||||
|
||||
private DomPoxMessageContextFactory contextFactory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
contextFactory = new DomPoxMessageContextFactory();
|
||||
contextFactory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
public void testCreateContext() throws Exception {
|
||||
String content = "<content/>";
|
||||
MockTransportRequest transportRequest = new MockTransportRequest(content.getBytes("UTF-8"));
|
||||
MockTransportContext transportContext = new MockTransportContext(transportRequest);
|
||||
DomPoxMessageContext context = (DomPoxMessageContext) contextFactory.createContext(transportContext);
|
||||
assertNotNull("No context returned", context);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.pox.dom;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.mock.MockTransportResponse;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class DomPoxMessageContextTest extends XMLTestCase {
|
||||
|
||||
private DomPoxMessageContext context;
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Element element = document.createElementNS("http://springframework.org/spring-ws", "element");
|
||||
document.appendChild(element);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
MockTransportRequest transportRequest = new MockTransportRequest();
|
||||
context = new DomPoxMessageContext(document, transportRequest, documentBuilder, transformer);
|
||||
}
|
||||
|
||||
public void testGetRequest() throws Exception {
|
||||
WebServiceMessage message = context.getRequest();
|
||||
assertNotNull("No request returned", message);
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(message.getPayloadSource(), result);
|
||||
assertXMLEqual("<element xmlns='http://springframework.org/spring-ws'/>", result.toString());
|
||||
}
|
||||
|
||||
public void testGetResponse() throws Exception {
|
||||
WebServiceMessage message = context.getResponse();
|
||||
assertNotNull("No request returned", message);
|
||||
}
|
||||
|
||||
public void testSendResponse() throws Exception {
|
||||
WebServiceMessage message = context.getResponse();
|
||||
String content = "<element xmlns='http://springframework.org/spring-ws'/>";
|
||||
StringSource source = new StringSource(content);
|
||||
transformer.transform(source, message.getPayloadResult());
|
||||
MockTransportResponse transportResponse = new MockTransportResponse();
|
||||
context.sendResponse(transportResponse);
|
||||
assertXMLEqual(transportResponse.getContents(), content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2006 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.pox.dom;
|
||||
|
||||
import org.springframework.ws.AbstractWebServiceMessageFactoryTestCase;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
public class DomPoxMessageFactoryTest extends AbstractWebServiceMessageFactoryTestCase {
|
||||
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
DomPoxMessageFactory factory = new DomPoxMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap;
|
||||
|
||||
import org.springframework.ws.AbstractWebServiceMessageFactoryTestCase;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
public abstract class AbstractSoapMessageFactoryTestCase extends AbstractWebServiceMessageFactoryTestCase {
|
||||
|
||||
public void testCreateEmptySoapMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,9 +26,10 @@ import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
|
||||
@@ -40,10 +41,13 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
|
||||
private SoapEndpointInterceptor interceptorMock;
|
||||
|
||||
private SaajSoapMessageFactory factory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
interceptorControl = MockControl.createControl(SoapEndpointInterceptor.class);
|
||||
interceptorMock = (SoapEndpointInterceptor) interceptorControl.getMock();
|
||||
dispatcher = new SoapMessageDispatcher();
|
||||
factory = new SaajSoapMessageFactory();
|
||||
}
|
||||
|
||||
public void testProcessMustUnderstandHeadersUnderstoodSoap11() throws Exception {
|
||||
@@ -53,8 +57,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
request.getSOAPHeader().addHeaderElement(new QName("http://www.springframework.org", "Header"));
|
||||
header.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
|
||||
header.setMustUnderstand(true);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
@@ -75,8 +80,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
request.getSOAPHeader().addHeaderElement(new QName("http://www.springframework.org", "Header"));
|
||||
header.setMustUnderstand(true);
|
||||
header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
@@ -97,8 +103,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
.addHeaderElement(new QName("http://www.springframework.org", "Header", "spring-ws"));
|
||||
header.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
|
||||
header.setMustUnderstand(true);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(false);
|
||||
@@ -110,7 +117,7 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertFalse("Header understood", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapBody responseBody = context.getSoapResponse().getSoapBody();
|
||||
SoapBody responseBody = ((SoapMessage) context.getResponse()).getSoapBody();
|
||||
assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) responseBody.getFault();
|
||||
assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "MustUnderstand"),
|
||||
@@ -129,8 +136,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
.addHeaderElement(new QName("http://www.springframework.org", "Header", "spring-ws"));
|
||||
header.setMustUnderstand(true);
|
||||
header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(false);
|
||||
@@ -142,7 +150,8 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertFalse("Header understood", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapBody responseBody = context.getSoapResponse().getSoapBody();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
SoapBody responseBody = response.getSoapBody();
|
||||
assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) responseBody.getFault();
|
||||
assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "MustUnderstand"),
|
||||
@@ -150,7 +159,7 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT,
|
||||
fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertEquals("Invalid fault actor", SOAPConstants.URI_SOAP_1_2_ROLE_NEXT, fault.getFaultActorOrRole());
|
||||
SoapHeader responseHeader = context.getSoapResponse().getSoapHeader();
|
||||
SoapHeader responseHeader = response.getSoapHeader();
|
||||
Iterator iterator = responseHeader.examineAllHeaderElements();
|
||||
assertTrue("Response header has no elements", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
@@ -167,8 +176,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
String headerActor = "http://www/springframework.org/role";
|
||||
header.setActor(headerActor);
|
||||
header.setMustUnderstand(true);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
@@ -182,7 +192,7 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
interceptorControl.verify();
|
||||
}
|
||||
|
||||
public void testProcessMustUnderstandHeadersForRoleSoap11() throws Exception {
|
||||
public void testProcessMustUnderstandHeadersForRoleSoap12() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
SOAPHeaderElement header = request.getSOAPHeader()
|
||||
@@ -190,8 +200,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
String headerRole = "http://www/springframework.org/role";
|
||||
header.setRole(headerRole);
|
||||
header.setMustUnderstand(true);
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
@@ -209,8 +220,9 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
request.getSOAPHeader().detachNode();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(request, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(request), factory);
|
||||
interceptorControl.replay();
|
||||
|
||||
SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(),
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.soap.context.AbstractSoap11MessageContextFactoryTestCase;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
|
||||
|
||||
public class AxiomSoap11MessageContextFactoryTest extends AbstractSoap11MessageContextFactoryTestCase {
|
||||
public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryTestCase {
|
||||
|
||||
protected MessageContextFactory createSoapMessageContextFactory() {
|
||||
return new AxiomSoapMessageContextFactory();
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
AxiomSoapMessageFactory factory = new AxiomSoapMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
|
||||
public void testCreateContextAttachment() throws Exception {
|
||||
// Axiom 1.1.1 has a fatal bug with regard to SwA
|
||||
public void testCreateSoapMessageAttachment() throws Exception {
|
||||
// Axiom 1.1.1 has a fatal bug with regard to SwA
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.soap.context.AbstractSoap12MessageContextFactoryTestCase;
|
||||
|
||||
public class AxiomSoap12MessageContextFactoryTest extends AbstractSoap12MessageContextFactoryTestCase {
|
||||
|
||||
protected MessageContextFactory createSoapMessageContextFactory() {
|
||||
return new AxiomSoapMessageContextFactory();
|
||||
}
|
||||
|
||||
public void testCreateContextAttachments() throws Exception {
|
||||
// Axiom does not support SwA with SOAP 1.2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.axiom;
|
||||
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap12.AbstractSoap12MessageFactoryTestCase;
|
||||
|
||||
public class AxiomSoap12MessageFactoryTest extends AbstractSoap12MessageFactoryTestCase {
|
||||
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
AxiomSoapMessageFactory factory = new AxiomSoapMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
|
||||
public void testCreateEmptyMessage() throws Exception {
|
||||
}
|
||||
|
||||
public void testCreateSoapMessageAttachment() throws Exception {
|
||||
// Axiom does not support SwA with SOAP 1.2
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
|
||||
public abstract class AbstractSoap11MessageContextFactoryTestCase extends AbstractSoapMessageContextFactoryTestCase {
|
||||
|
||||
public void testCreateContextNoAttachment() throws Exception {
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type", "text/xml");
|
||||
headers.setProperty("SOAPAction", "\"Some-URI\"");
|
||||
MockTransportContext transportContext = createTransportContext(headers, "soap11.xml");
|
||||
|
||||
MessageContext messageContext = contextFactory.createContext(transportContext);
|
||||
SoapMessage requestMessage = (SoapMessage) messageContext.getRequest();
|
||||
assertNotNull("Request null", requestMessage);
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, requestMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateContextAttachment() throws Exception {
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type",
|
||||
"multipart/related; type=\"text/xml\"; boundary=\"----=_Part_0_11416420.1149699787554\"");
|
||||
MockTransportContext transportContext = createTransportContext(headers, "soap11-attachment.bin");
|
||||
|
||||
MessageContext messageContext = contextFactory.createContext(transportContext);
|
||||
SoapMessage requestMessage = (SoapMessage) messageContext.getRequest();
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, requestMessage.getVersion());
|
||||
Attachment attachment = requestMessage.getAttachment("interface21");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
|
||||
public abstract class AbstractSoap11MessageContextTestCase extends AbstractSoapMessageContextTestCase {
|
||||
|
||||
public void testWriteToTransportResponse() throws Exception {
|
||||
messageContext.getResponse(); // create response
|
||||
messageContext.sendResponse(transportResponse);
|
||||
assertXMLEqual("<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Header/><Body/></Envelope>",
|
||||
transportResponse.getContents());
|
||||
assertTrue("Invalid Content-Type set", transportResponse.getHeaders().getProperty("Content-Type")
|
||||
.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponseAttachment() throws Exception {
|
||||
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
|
||||
messageContext.getSoapResponse().addAttachment(inputStreamSource, "text/plain");
|
||||
messageContext.sendResponse(transportResponse);
|
||||
assertTrue("Invalid Content-Type set", transportResponse.getHeaders().getProperty("Content-Type")
|
||||
.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package org.springframework.ws.soap.context;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
|
||||
public abstract class AbstractSoap12MessageContextFactoryTestCase extends AbstractSoapMessageContextFactoryTestCase {
|
||||
|
||||
public void testCreateContextNoAttachment() throws Exception {
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type", "application/soap+xml");
|
||||
headers.setProperty("SOAPAction", "\"Some-URI\"");
|
||||
MockTransportContext transportContext = createTransportContext(headers, "soap12.xml");
|
||||
|
||||
MessageContext messageContext = contextFactory.createContext(transportContext);
|
||||
SoapMessage requestMessage = (SoapMessage) messageContext.getRequest();
|
||||
assertNotNull("Request null", requestMessage);
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, requestMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateContextAttachments() throws Exception {
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type",
|
||||
"multipart/related; type=\"application/soap+xml\"; boundary=\"----=_Part_0_11416420.1149699787554\"");
|
||||
MockTransportContext transportContext = createTransportContext(headers, "soap12-attachment.bin");
|
||||
|
||||
MessageContext messageContext = contextFactory.createContext(transportContext);
|
||||
SoapMessage requestMessage = (SoapMessage) messageContext.getRequest();
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, requestMessage.getVersion());
|
||||
Attachment attachment = requestMessage.getAttachment("interface21");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
|
||||
public abstract class AbstractSoap12MessageContextTestCase extends AbstractSoapMessageContextTestCase {
|
||||
|
||||
public void testWriteToTransportResponse() throws Exception {
|
||||
messageContext.getResponse(); // create response
|
||||
messageContext.sendResponse(transportResponse);
|
||||
assertXMLEqual("<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Header/><Body/></Envelope>",
|
||||
transportResponse.getContents());
|
||||
assertTrue("Invalid Content-Type set", transportResponse.getHeaders().getProperty("Content-Type")
|
||||
.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponseAttachment() throws Exception {
|
||||
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
|
||||
messageContext.getSoapResponse().addAttachment(inputStreamSource, "text/plain");
|
||||
messageContext.sendResponse(transportResponse);
|
||||
assertTrue("Invalid Content-Type set", transportResponse.getHeaders().getProperty("Content-Type")
|
||||
.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.springframework.ws.soap.context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
|
||||
public abstract class AbstractSoapMessageContextFactoryTestCase extends TestCase {
|
||||
|
||||
protected MessageContextFactory contextFactory;
|
||||
|
||||
protected final void setUp() throws Exception {
|
||||
contextFactory = createSoapMessageContextFactory();
|
||||
if (contextFactory instanceof InitializingBean) {
|
||||
((InitializingBean) contextFactory).afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
protected MockTransportContext createTransportContext(Properties headers, String requestFile) throws IOException {
|
||||
byte[] contents = FileCopyUtils
|
||||
.copyToByteArray(AbstractSoapMessageContextFactoryTestCase.class.getResourceAsStream(requestFile));
|
||||
return new MockTransportContext(new MockTransportRequest(headers, contents));
|
||||
}
|
||||
|
||||
protected abstract MessageContextFactory createSoapMessageContextFactory() throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.context;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.mock.MockTransportResponse;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
public abstract class AbstractSoapMessageContextTestCase extends XMLTestCase {
|
||||
|
||||
protected SoapMessageContext messageContext;
|
||||
|
||||
protected Transformer transformer;
|
||||
|
||||
protected MockTransportResponse transportResponse;
|
||||
|
||||
protected final void setUp() throws Exception {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
TransportRequest transportRequest = new MockTransportRequest();
|
||||
transportResponse = new MockTransportResponse();
|
||||
messageContext = createMessageContext(transportRequest);
|
||||
}
|
||||
|
||||
protected abstract SoapMessageContext createMessageContext(TransportRequest transportRequest) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
@@ -20,17 +20,18 @@ import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.soap.soap11.Soap11Body;
|
||||
|
||||
public class SimpleSoapExceptionResolverTest extends TestCase {
|
||||
|
||||
private SimpleSoapExceptionResolver exceptionResolver;
|
||||
|
||||
private MockControl contextControl;
|
||||
|
||||
private SoapMessageContext contextMock;
|
||||
private MessageContext messageContext;
|
||||
|
||||
private MockControl messageControl;
|
||||
|
||||
@@ -40,10 +41,15 @@ public class SimpleSoapExceptionResolverTest extends TestCase {
|
||||
|
||||
private Soap11Body bodyMock;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
exceptionResolver = new SimpleSoapExceptionResolver();
|
||||
contextControl = MockControl.createControl(SoapMessageContext.class);
|
||||
contextMock = (SoapMessageContext) contextControl.getMock();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
messageContext = new DefaultMessageContext(new MockWebServiceMessage(), factoryMock);
|
||||
messageControl = MockControl.createControl(SoapMessage.class);
|
||||
messageMock = (SoapMessage) messageControl.getMock();
|
||||
bodyControl = MockControl.createControl(Soap11Body.class);
|
||||
@@ -53,15 +59,15 @@ public class SimpleSoapExceptionResolverTest extends TestCase {
|
||||
|
||||
public void testResolveExceptionInternal() throws Exception {
|
||||
Exception exception = new Exception("message");
|
||||
contextControl.expectAndReturn(contextMock.getSoapResponse(), messageMock);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), messageMock);
|
||||
messageControl.expectAndReturn(messageMock.getSoapBody(), bodyMock);
|
||||
bodyControl.expectAndReturn(bodyMock.addServerOrReceiverFault(exception.getMessage(), Locale.ENGLISH), null);
|
||||
contextControl.replay();
|
||||
factoryControl.replay();
|
||||
messageControl.replay();
|
||||
bodyControl.replay();
|
||||
boolean result = exceptionResolver.resolveExceptionInternal(contextMock, null, exception);
|
||||
boolean result = exceptionResolver.resolveExceptionInternal(messageContext, null, exception);
|
||||
assertTrue("Invalid result", result);
|
||||
contextControl.verify();
|
||||
factoryControl.verify();
|
||||
messageControl.verify();
|
||||
bodyControl.verify();
|
||||
}
|
||||
|
||||
@@ -23,12 +23,13 @@ import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapMessageException;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessage;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
|
||||
@@ -36,8 +37,12 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
|
||||
private SoapFaultMappingExceptionResolver resolver;
|
||||
|
||||
private SaajSoapMessageFactory factory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
resolver = new SoapFaultMappingExceptionResolver();
|
||||
factory = new SaajSoapMessageFactory();
|
||||
|
||||
}
|
||||
|
||||
public void testGetDepth() throws Exception {
|
||||
@@ -56,13 +61,14 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(message, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
@@ -79,13 +85,14 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(message, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
@@ -102,13 +109,14 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(message, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
@@ -125,13 +133,14 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(message, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(),
|
||||
@@ -150,13 +159,14 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
resolver.setDefaultFault(defaultFault);
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
SaajSoapMessageContext context =
|
||||
new Saaj13SoapMessageContext(message, new MockTransportRequest(), messageFactory);
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
MessageContext context = new DefaultMessageContext(new Saaj13SoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = context.getSoapResponse();
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
|
||||
@@ -16,18 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.endpoint.interceptor;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.log4j.AppenderSkeleton;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageContext;
|
||||
import org.springframework.ws.soap.saaj.saaj13.Saaj13SoapMessageContext;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class SoapEnvelopeLoggingInterceptorTest extends TestCase {
|
||||
|
||||
@@ -35,16 +32,16 @@ public class SoapEnvelopeLoggingInterceptorTest extends TestCase {
|
||||
|
||||
private CountingAppender appender;
|
||||
|
||||
private SaajSoapMessageContext messageContext;
|
||||
private MessageContext messageContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
interceptor = new SoapEnvelopeLoggingInterceptor();
|
||||
appender = new SoapEnvelopeLoggingInterceptorTest.CountingAppender();
|
||||
BasicConfigurator.configure(appender);
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
messageContext = new Saaj13SoapMessageContext(saajMessage, new MockTransportRequest(), messageFactory);
|
||||
SaajSoapMessageFactory factory = new SaajSoapMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
messageContext = new DefaultMessageContext(factory);
|
||||
appender.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.EndpointInvocationChain;
|
||||
import org.springframework.ws.EndpointMapping;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapEndpointInvocationChain;
|
||||
|
||||
public class DelegatingSoapEndpointMappingTest extends TestCase {
|
||||
@@ -41,7 +43,7 @@ public class DelegatingSoapEndpointMappingTest extends TestCase {
|
||||
public void testGetEndpointMapping() throws Exception {
|
||||
String role = "http://www.springframework.org/spring-ws/role";
|
||||
endpointMapping.setActorOrRole(role);
|
||||
MockMessageContext context = new MockMessageContext();
|
||||
MessageContext context = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
EndpointInvocationChain delegateChain = new EndpointInvocationChain(new Object());
|
||||
control.expectAndReturn(mock.getEndpoint(context), delegateChain);
|
||||
control.replay();
|
||||
|
||||
@@ -16,36 +16,54 @@
|
||||
|
||||
package org.springframework.ws.soap.endpoint.mapping;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.mock.MockMessageContext;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.mock.MockTransportRequest;
|
||||
import org.springframework.ws.mock.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.transport.SimpleTransportContext;
|
||||
import org.springframework.ws.transport.StubTransportInputStream;
|
||||
import org.springframework.ws.transport.StubTransportOutputStream;
|
||||
import org.springframework.ws.transport.TransportContext;
|
||||
import org.springframework.ws.transport.TransportContextHolder;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
public class SoapActionEndpointMappingTest extends TestCase {
|
||||
|
||||
private SoapActionEndpointMapping mapping;
|
||||
|
||||
private MockTransportRequest request;
|
||||
private MessageContext context;
|
||||
|
||||
private MockMessageContext context;
|
||||
private Map headers;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
request = new MockTransportRequest();
|
||||
MockTransportContext transportContext = new MockTransportContext(request);
|
||||
context = new MockMessageContext(new MockWebServiceMessage(), transportContext);
|
||||
headers = new HashMap();
|
||||
TransportInputStream tis = new StubTransportInputStream(new ByteArrayInputStream(new byte[0]), headers);
|
||||
TransportOutputStream tos = new StubTransportOutputStream(new ByteArrayOutputStream());
|
||||
TransportContext transportContext = new SimpleTransportContext(tis, tos);
|
||||
TransportContextHolder.setTransportContext(transportContext);
|
||||
mapping = new SoapActionEndpointMapping();
|
||||
context = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
TransportContextHolder.setTransportContext(null);
|
||||
}
|
||||
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/SoapAction";
|
||||
request.addHeader(SoapActionEndpointMapping.SOAP_ACTION_HEADER, soapAction);
|
||||
headers.put(SoapActionEndpointMapping.SOAP_ACTION_HEADER, soapAction);
|
||||
assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
}
|
||||
|
||||
public void testGetLookupKeyForMessageQuoted() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/SoapAction";
|
||||
request.addHeader(SoapActionEndpointMapping.SOAP_ACTION_HEADER, "\"" + soapAction + "\"");
|
||||
headers.put(SoapActionEndpointMapping.SOAP_ACTION_HEADER, "\"" + soapAction + "\"");
|
||||
assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
|
||||
|
||||
public class SaajSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryTestCase {
|
||||
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
SaajSoapMessageFactory factory = new SaajSoapMessageFactory();
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.ws.soap.saaj;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.soap.context.AbstractSoap12MessageContextFactoryTestCase;
|
||||
|
||||
public class SaajSoap12MessageContextFactoryTest extends AbstractSoap12MessageContextFactoryTestCase {
|
||||
|
||||
protected MessageContextFactory createSoapMessageContextFactory() throws Exception {
|
||||
SaajSoapMessageContextFactory contextFactory = new SaajSoapMessageContextFactory();
|
||||
contextFactory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
return contextFactory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap12.AbstractSoap12MessageFactoryTestCase;
|
||||
|
||||
public class SaajSoap12MessageFactoryTest extends AbstractSoap12MessageFactoryTestCase {
|
||||
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
SaajSoapMessageFactory factory = new SaajSoapMessageFactory();
|
||||
factory.setSoapProtocol(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj.saaj12;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.springframework.ws.soap.context.AbstractSoap11MessageContextTestCase;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
public class Saaj12Soap11MessageContextTest extends AbstractSoap11MessageContextTestCase {
|
||||
|
||||
protected SoapMessageContext createMessageContext(TransportRequest transportRequest) throws SOAPException {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
return new Saaj12SoapMessageContext(messageFactory.createMessage(), transportRequest, messageFactory);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj.saaj13;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.springframework.ws.soap.context.AbstractSoap11MessageContextTestCase;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
public class Saaj13Soap11MessageContextTest extends AbstractSoap11MessageContextTestCase {
|
||||
|
||||
protected SoapMessageContext createMessageContext(TransportRequest transportRequest) throws SOAPException {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
return new Saaj13SoapMessageContext(messageFactory.createMessage(), transportRequest, messageFactory);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.saaj.saaj13;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.springframework.ws.soap.context.AbstractSoap12MessageContextTestCase;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
import org.springframework.ws.transport.TransportRequest;
|
||||
|
||||
public class Saaj13Soap12MessageContextTest extends AbstractSoap12MessageContextTestCase {
|
||||
|
||||
protected SoapMessageContext createMessageContext(TransportRequest transportRequest) throws SOAPException {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
return new Saaj13SoapMessageContext(messageFactory.createMessage(), transportRequest, messageFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.soap11;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.AbstractSoapMessageFactoryTestCase;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.StubTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
|
||||
|
||||
public void testCreateEmptyMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateSoapMessageNoAttachment() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11.xml");
|
||||
final Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type", "text/xml");
|
||||
TransportInputStream tis = new StubTransportInputStream(is, headers);
|
||||
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateSoapMessageAttachment() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11-attachment.bin");
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type",
|
||||
"multipart/related; type=\"text/xml\"; boundary=\"----=_Part_0_11416420.1149699787554\"");
|
||||
TransportInputStream tis = new StubTransportInputStream(is, headers);
|
||||
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
Attachment attachment = soapMessage.getAttachment("interface21");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -17,12 +17,16 @@
|
||||
package org.springframework.ws.soap.soap11;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.soap.AbstractSoapMessageTestCase;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.StubTransportOutputStream;
|
||||
|
||||
public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageTestCase {
|
||||
|
||||
@@ -40,4 +44,28 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT
|
||||
assertXMLEqual("<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Header/><Body/></Envelope>",
|
||||
new String(outputStream.toByteArray(), "UTF-8"));
|
||||
}
|
||||
|
||||
public void testWriteToTransportOutputStream() throws Exception {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
StubTransportOutputStream tos = new StubTransportOutputStream(bos);
|
||||
soapMessage.writeTo(tos);
|
||||
String result = bos.toString("UTF-8");
|
||||
assertXMLEqual("<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Header/><Body/></Envelope>",
|
||||
result);
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponseAttachment() throws Exception {
|
||||
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
|
||||
soapMessage.addAttachment(inputStreamSource, "text/plain");
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
final Properties headers = new Properties();
|
||||
StubTransportOutputStream tos = new StubTransportOutputStream(bos);
|
||||
soapMessage.writeTo(tos);
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2006 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.soap.soap12;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.soap.AbstractSoapMessageFactoryTestCase;
|
||||
import org.springframework.ws.soap.Attachment;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.StubTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
public abstract class AbstractSoap12MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
|
||||
|
||||
public void testCreateEmptyMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateSoapMessageNoAttachment() throws Exception {
|
||||
InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12.xml");
|
||||
final Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type", "application/soap+xml");
|
||||
TransportInputStream tis = new StubTransportInputStream(is, headers);
|
||||
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
|
||||
}
|
||||
|
||||
public void testCreateSoapMessageAttachment() throws Exception {
|
||||
InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12-attachment.bin");
|
||||
Properties headers = new Properties();
|
||||
headers.setProperty("Content-Type",
|
||||
"multipart/related; type=\"application/soap+xml\"; boundary=\"----=_Part_0_11416420.1149699787554\"");
|
||||
TransportInputStream tis = new StubTransportInputStream(is, headers);
|
||||
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
|
||||
Attachment attachment = soapMessage.getAttachment("interface21");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -19,10 +19,13 @@ package org.springframework.ws.soap.soap12;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.soap.AbstractSoapMessageTestCase;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.StubTransportOutputStream;
|
||||
|
||||
public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageTestCase {
|
||||
|
||||
@@ -42,5 +45,26 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT
|
||||
new ClassPathResource("soap12.xsd", AbstractSoap12MessageTestCase.class)};
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponse() throws Exception {
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
StubTransportOutputStream tos = new StubTransportOutputStream(bos);
|
||||
soapMessage.writeTo(tos);
|
||||
String result = bos.toString("UTF-8");
|
||||
|
||||
assertXMLEqual("<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Header/><Body/></Envelope>", result);
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponseAttachment() throws Exception {
|
||||
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
|
||||
soapMessage.addAttachment(inputStreamSource, "text/plain");
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
StubTransportOutputStream tos = new StubTransportOutputStream(bos);
|
||||
soapMessage.writeTo(tos);
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class StubTransportInputStream extends TransportInputStream {
|
||||
|
||||
private Map headers;
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
public StubTransportInputStream(InputStream inputStream, Map headers) {
|
||||
Assert.notNull(inputStream, "inputStream must not be null");
|
||||
Assert.notNull(headers, "headers must not be null");
|
||||
this.inputStream = inputStream;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
protected InputStream getInputStream() throws IOException {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public Iterator getHeaderNames() throws IOException {
|
||||
return headers.keySet().iterator();
|
||||
}
|
||||
|
||||
public Iterator getHeaders(String name) throws IOException {
|
||||
return Collections.singleton(headers.get(name)).iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2006 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class StubTransportOutputStream extends TransportOutputStream {
|
||||
|
||||
private Map headers = new HashMap();
|
||||
|
||||
private OutputStream outputStream;
|
||||
|
||||
public StubTransportOutputStream(OutputStream outputStream) {
|
||||
Assert.notNull(outputStream, "outputStream must not be null");
|
||||
this.outputStream = outputStream;
|
||||
}
|
||||
|
||||
protected OutputStream getOutputStream() throws IOException {
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
public Map getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void addHeader(String name, String value) throws IOException {
|
||||
headers.put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2006 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.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
public class HttpServletTransportInputStreamTest extends TestCase {
|
||||
|
||||
private HttpServletTransportInputStream tis;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private byte[] content;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
content = "content".getBytes("UTF-8");
|
||||
request.setContent(content);
|
||||
tis = new HttpServletTransportInputStream(request);
|
||||
}
|
||||
|
||||
public void testReadInputStream() throws Exception {
|
||||
request.setContent(content);
|
||||
byte[] result = FileCopyUtils.copyToByteArray(tis);
|
||||
assertTrue("Invalid contents", Arrays.equals(content, result));
|
||||
}
|
||||
|
||||
public void testHeaders() throws Exception {
|
||||
String headerName = "Header";
|
||||
String headerValue = "Value";
|
||||
request.addHeader(headerName, headerValue);
|
||||
Iterator iterator = tis.getHeaderNames();
|
||||
assertTrue("No headers found", iterator.hasNext());
|
||||
assertEquals("Invalid header", headerName, iterator.next());
|
||||
iterator = tis.getHeaders(headerName);
|
||||
assertTrue("No header values found", iterator.hasNext());
|
||||
assertEquals("Invalid header value", headerValue, iterator.next());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2006 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.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
public class HttpServletTransportOutputStreamTest extends TestCase {
|
||||
|
||||
private HttpServletTransportOutputStream tos;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
response = new MockHttpServletResponse();
|
||||
tos = new HttpServletTransportOutputStream(response);
|
||||
}
|
||||
|
||||
public void testWriteOutputStream() throws Exception {
|
||||
byte[] content = "content".getBytes("UTF-8");
|
||||
FileCopyUtils.copy(content, tos);
|
||||
assertTrue("Invalid contents", Arrays.equals(content, response.getContentAsByteArray()));
|
||||
}
|
||||
|
||||
public void testHeaders() throws Exception {
|
||||
String headerName = "Header";
|
||||
String headerValue = "Value";
|
||||
tos.addHeader(headerName, headerValue);
|
||||
assertTrue("No header set", response.getHeaderNames().contains(headerName));
|
||||
assertEquals("Invalid header value set", Collections.singletonList(headerValue),
|
||||
response.getHeaders(headerName));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.springframework.ws.transport.http;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
public class HttpTransportRequestTest extends TestCase {
|
||||
|
||||
private HttpTransportRequest transportRequest;
|
||||
|
||||
private MockHttpServletRequest mockRequest;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
mockRequest = new MockHttpServletRequest();
|
||||
transportRequest = new HttpTransportRequest(mockRequest);
|
||||
}
|
||||
|
||||
public void testGetHttpServletRequest() throws Exception {
|
||||
assertEquals("Invalid request", mockRequest, transportRequest.getHttpServletRequest());
|
||||
}
|
||||
|
||||
public void testGetHeaderNames() throws Exception {
|
||||
mockRequest.addHeader("header1", "value11");
|
||||
mockRequest.addHeader("header1", "value12");
|
||||
mockRequest.addHeader("header2", "value2");
|
||||
Iterator headers = transportRequest.getHeaderNames();
|
||||
assertTrue("Invalid amount of header names", headers.hasNext());
|
||||
String header = (String) headers.next();
|
||||
assertTrue("Invalid header", "header1".equals(header) || "header2".equals(header));
|
||||
assertTrue("Invalid amount of header names", headers.hasNext());
|
||||
header = (String) headers.next();
|
||||
assertTrue("Invalid header", "header1".equals(header) || "header2".equals(header));
|
||||
assertFalse("Invalid amount of header names", headers.hasNext());
|
||||
}
|
||||
|
||||
public void testGetHeaders() throws Exception {
|
||||
mockRequest.addHeader("header", "value1");
|
||||
mockRequest.addHeader("header", "value2");
|
||||
Iterator values = transportRequest.getHeaders("header");
|
||||
assertTrue("Invalid amount of header names", values.hasNext());
|
||||
String value = (String) values.next();
|
||||
assertTrue("Invalid value", "value1".equals(value) || "value2".equals(value));
|
||||
assertTrue("Invalid amount of header names", values.hasNext());
|
||||
value = (String) values.next();
|
||||
assertTrue("Invalid value", "value1".equals(value) || "value2".equals(value));
|
||||
assertFalse("Invalid amount of header names", values.hasNext());
|
||||
}
|
||||
|
||||
public void testGetURL() throws Exception {
|
||||
mockRequest.setScheme("http");
|
||||
mockRequest.setServerName("www.example.com");
|
||||
mockRequest.setServerPort(8080);
|
||||
mockRequest.setRequestURI("/services/Service");
|
||||
String url = transportRequest.getUrl();
|
||||
assertNotNull("No url returned", url);
|
||||
assertEquals("Invalid url returned", "http://www.example.com:8080/services/Service", url);
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,11 @@ import org.easymock.MockControl;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ws.NoEndpointFoundException;
|
||||
import org.springframework.ws.context.MessageContextFactory;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.endpoint.MessageEndpoint;
|
||||
import org.springframework.ws.mock.MockTransportContext;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.context.SoapMessageContext;
|
||||
|
||||
public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
|
||||
@@ -45,54 +44,50 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
|
||||
private MockHttpServletResponse httpResponse;
|
||||
|
||||
private MockControl endpointControl;
|
||||
|
||||
private MessageEndpoint endpointMock;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private MessageContextFactory factoryMock;
|
||||
|
||||
private MockControl contextControl;
|
||||
|
||||
private SoapMessageContext contextMock;
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
private MockControl messageControl;
|
||||
|
||||
private SoapMessage messageMock;
|
||||
private SoapMessage responseMock;
|
||||
|
||||
private MockControl bodyControl;
|
||||
|
||||
private SoapBody bodyMock;
|
||||
|
||||
private SoapMessage requestMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
adapter = new MessageEndpointHandlerAdapter();
|
||||
httpRequest = new MockHttpServletRequest();
|
||||
httpResponse = new MockHttpServletResponse();
|
||||
endpointControl = MockControl.createControl(MessageEndpoint.class);
|
||||
endpointMock = (MessageEndpoint) endpointControl.getMock();
|
||||
factoryControl = MockControl.createControl(MessageContextFactory.class);
|
||||
factoryMock = (MessageContextFactory) factoryControl.getMock();
|
||||
adapter.setMessageContextFactory(factoryMock);
|
||||
contextControl = MockControl.createControl(SoapMessageContext.class);
|
||||
contextMock = (SoapMessageContext) contextControl.getMock();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
adapter.setMessageFactory(factoryMock);
|
||||
messageControl = MockControl.createControl(SoapMessage.class);
|
||||
messageMock = (SoapMessage) messageControl.getMock();
|
||||
requestMock = (SoapMessage) messageControl.getMock();
|
||||
responseMock = (SoapMessage) messageControl.getMock();
|
||||
bodyControl = MockControl.createControl(SoapBody.class);
|
||||
bodyMock = (SoapBody) bodyControl.getMock();
|
||||
}
|
||||
|
||||
public void testHandleNonPost() throws Exception {
|
||||
httpRequest.setMethod("GET");
|
||||
endpointControl.replay();
|
||||
replayMockControls();
|
||||
MessageEndpoint endpoint = new MessageEndpoint() {
|
||||
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
}
|
||||
};
|
||||
try {
|
||||
adapter.handle(httpRequest, httpResponse, endpointMock);
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
fail("ServletException expected");
|
||||
}
|
||||
catch (ServletException ex) {
|
||||
// expected
|
||||
}
|
||||
endpointControl.verify();
|
||||
verifyMockControls();
|
||||
}
|
||||
|
||||
public void testHandlePostNoResponse() throws Exception {
|
||||
@@ -100,16 +95,18 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
httpRequest.setContent(MessageEndpointHandlerAdapterTest.REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
endpointMock.invoke(null);
|
||||
endpointControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryMock.createContext(new MockTransportContext());
|
||||
factoryMock.createWebServiceMessage(new HttpServletTransportInputStream(httpRequest));
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(contextMock);
|
||||
contextControl.expectAndReturn(contextMock.hasResponse(), false);
|
||||
factoryControl.setReturnValue(responseMock);
|
||||
|
||||
replayMockControls();
|
||||
MessageEndpoint endpoint = new MessageEndpoint() {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpointMock);
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
}
|
||||
};
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_NO_CONTENT, httpResponse.getStatus());
|
||||
assertEquals("Response written", 0, httpResponse.getContentAsString().length());
|
||||
@@ -121,21 +118,24 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
httpRequest.setContent(MessageEndpointHandlerAdapterTest.REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
endpointMock.invoke(null);
|
||||
endpointControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryMock.createContext(new MockTransportContext());
|
||||
factoryMock.createWebServiceMessage(new HttpServletTransportInputStream(httpRequest));
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(contextMock);
|
||||
contextControl.expectAndReturn(contextMock.hasResponse(), true);
|
||||
contextControl.expectAndReturn(contextMock.getResponse(), messageMock);
|
||||
messageControl.expectAndReturn(messageMock.getSoapBody(), bodyMock);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), responseMock);
|
||||
messageControl.expectAndReturn(responseMock.getSoapBody(), bodyMock);
|
||||
bodyControl.expectAndReturn(bodyMock.hasFault(), false);
|
||||
contextMock.sendResponse(new HttpTransportResponse(httpResponse));
|
||||
contextControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
responseMock.writeTo(new HttpServletTransportOutputStream(httpResponse));
|
||||
messageControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
|
||||
replayMockControls();
|
||||
MessageEndpoint endpoint = new MessageEndpoint() {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpointMock);
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
messageContext.getResponse();
|
||||
}
|
||||
};
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_OK, httpResponse.getStatus());
|
||||
verifyMockControls();
|
||||
@@ -146,24 +146,26 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
httpRequest.setContent(MessageEndpointHandlerAdapterTest.REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
endpointMock.invoke(null);
|
||||
endpointControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryMock.createContext(new MockTransportContext());
|
||||
factoryMock.createWebServiceMessage(new HttpServletTransportInputStream(httpRequest));
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(contextMock);
|
||||
contextControl.expectAndReturn(contextMock.hasResponse(), true);
|
||||
contextControl.expectAndReturn(contextMock.getResponse(), messageMock);
|
||||
messageControl.expectAndReturn(messageMock.getSoapBody(), bodyMock);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), responseMock);
|
||||
messageControl.expectAndReturn(responseMock.getSoapBody(), bodyMock);
|
||||
bodyControl.expectAndReturn(bodyMock.hasFault(), true);
|
||||
contextMock.sendResponse(null);
|
||||
contextControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
responseMock.writeTo(new HttpServletTransportOutputStream(httpResponse));
|
||||
messageControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
|
||||
replayMockControls();
|
||||
MessageEndpoint endpoint = new MessageEndpoint() {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpointMock);
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
messageContext.getResponse();
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals("Invalid status code on response",
|
||||
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
httpResponse.getStatus());
|
||||
verifyMockControls();
|
||||
}
|
||||
@@ -173,16 +175,20 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
httpRequest.setContent(MessageEndpointHandlerAdapterTest.REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
endpointMock.invoke(null);
|
||||
endpointControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
endpointControl.setThrowable(new NoEndpointFoundException(null));
|
||||
factoryMock.createContext(new MockTransportContext());
|
||||
factoryMock.createWebServiceMessage(new HttpServletTransportInputStream(httpRequest));
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(contextMock);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
|
||||
replayMockControls();
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpointMock);
|
||||
MessageEndpoint endpoint = new MessageEndpoint() {
|
||||
|
||||
public void invoke(MessageContext messageContext) throws Exception {
|
||||
throw new NoEndpointFoundException(messageContext.getRequest());
|
||||
}
|
||||
};
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
assertEquals("No 404 returned", HttpServletResponse.SC_NOT_FOUND, httpResponse.getStatus());
|
||||
|
||||
verifyMockControls();
|
||||
@@ -190,17 +196,13 @@ public class MessageEndpointHandlerAdapterTest extends TestCase {
|
||||
}
|
||||
|
||||
private void replayMockControls() {
|
||||
endpointControl.replay();
|
||||
factoryControl.replay();
|
||||
contextControl.replay();
|
||||
messageControl.replay();
|
||||
bodyControl.replay();
|
||||
}
|
||||
|
||||
private void verifyMockControls() {
|
||||
endpointControl.verify();
|
||||
factoryControl.verify();
|
||||
contextControl.verify();
|
||||
messageControl.verify();
|
||||
bodyControl.verify();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user