You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/15 10:39:18 UTC
svn commit: r386019 -
/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Author: gnodet
Date: Wed Mar 15 01:39:17 2006
New Revision: 386019
URL: http://svn.apache.org/viewcvs?rev=386019&view=rev
Log:
Invalid content length may be sent
Modified:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=386019&r1=386018&r2=386019&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java Wed Mar 15 01:39:17 2006
@@ -69,22 +69,20 @@
public ProviderProcessor(HttpEndpoint endpoint) {
try {
- this.endpoint = endpoint;
+ this.endpoint = endpoint;
this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
this.jbiMarshaler = new JBIMarshaler();
- this.host = new HostConfiguration();
- this.host.setHost(new URI(endpoint.getLocationURI(), false));
- } catch (URIException e) {
- throw new RuntimeException(e);
- }
+ this.host = new HostConfiguration();
+ this.host.setHost(new URI(endpoint.getLocationURI(), false));
+ } catch (URIException e) {
+ throw new RuntimeException(e);
+ }
}
public void process(MessageExchange exchange) throws Exception {
if (exchange.getStatus() == ExchangeStatus.DONE) {
return;
} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
- exchange.setStatus(ExchangeStatus.DONE);
- channel.send(exchange);
return;
}
PostMethod method = new PostMethod(endpoint.getLocationURI());
@@ -94,39 +92,45 @@
SoapWriter writer = soapMarshaler.createWriter(soapMessage);
Map headers = (Map) nm.getProperty(JbiConstants.PROTOCOL_HEADERS);
if (headers != null) {
- for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
- String name = (String) it.next();
- String value = (String) headers.get(name);
- method.addRequestHeader(name, value);
- }
+ for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+ String name = (String) it.next();
+ String value = (String) headers.get(name);
+ method.addRequestHeader(name, value);
+ }
}
- method.addRequestHeader("Content-Type", writer.getContentType());
- method.setRequestEntity(writeMessage(writer));
+ RequestEntity entity = writeMessage(writer);
+ method.addRequestHeader("Content-Type", entity.getContentType());
+ if (entity.getContentLength() < 0) {
+ method.removeRequestHeader("Content-Length");
+ } else {
+ method.addRequestHeader("Content-Length", Long.toString(entity.getContentLength()));
+ }
+ method.setRequestEntity(entity);
try {
int response = getClient().executeMethod(host, method);
if (response != HttpStatus.SC_OK) {
- if (exchange instanceof InOnly == false) {
- Fault fault = exchange.createFault();
+ if (exchange instanceof InOnly == false) {
+ Fault fault = exchange.createFault();
SoapReader reader = soapMarshaler.createReader();
Header contentType = method.getResponseHeader("Content-Type");
soapMessage = reader.read(method.getResponseBodyAsStream(),
- contentType != null ? contentType.getValue() : null);
+ contentType != null ? contentType.getValue() : null);
fault.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
- jbiMarshaler.toNMS(fault, soapMessage);
- exchange.setFault(fault);
- exchange.setStatus(ExchangeStatus.ERROR);
- channel.send(exchange);
- return;
- } else {
- throw new Exception("Invalid status response: " + response);
- }
+ jbiMarshaler.toNMS(fault, soapMessage);
+ exchange.setFault(fault);
+ exchange.setStatus(ExchangeStatus.ERROR);
+ channel.send(exchange);
+ return;
+ } else {
+ throw new Exception("Invalid status response: " + response);
+ }
}
if (exchange instanceof InOut) {
NormalizedMessage msg = exchange.createMessage();
SoapReader reader = soapMarshaler.createReader();
Header contentType = method.getResponseHeader("Content-Type");
soapMessage = reader.read(method.getResponseBodyAsStream(),
- contentType != null ? contentType.getValue() : null);
+ contentType != null ? contentType.getValue() : null);
msg.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
jbiMarshaler.toNMS(msg, soapMessage);
((InOut) exchange).setOutMessage(msg);
@@ -162,34 +166,34 @@
}
protected Map getHeaders(HttpServletRequest request) {
- Map headers = new HashMap();
+ Map headers = new HashMap();
Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = request.getHeader(name);
headers.put(name, value);
}
- return headers;
- }
-
+ return headers;
+ }
+
protected Map getHeaders(HttpMethod method) {
- Map headers = new HashMap();
+ Map headers = new HashMap();
Header[] h = method.getResponseHeaders();
for (int i = 0; i < h.length; i++) {
- headers.put(h[i].getName(), h[i].getValue());
- }
- return headers;
- }
+ headers.put(h[i].getName(), h[i].getValue());
+ }
+ return headers;
+ }
protected RequestEntity writeMessage(SoapWriter writer) throws Exception {
- HttpLifeCycle lf = (HttpLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
- if (lf.getConfiguration().isStreamingEnabled()) {
- return new StreamingRequestEntity(writer);
- } else {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- writer.write(baos);
- return new ByteArrayRequestEntity(baos.toByteArray(), writer.getContentType());
- }
+ HttpLifeCycle lf = (HttpLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
+ if (lf.getConfiguration().isStreamingEnabled()) {
+ return new StreamingRequestEntity(writer);
+ } else {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writer.write(baos);
+ return new ByteArrayRequestEntity(baos.toByteArray(), writer.getContentType());
+ }
}
protected HttpClient getClient() {
@@ -211,7 +215,7 @@
public void writeRequest(OutputStream out) throws IOException {
try {
- writer.write(out);
+ writer.write(out);
out.flush();
} catch (Exception e) {
throw (IOException) new IOException("Could not write request").initCause(e);