this.configurationContext = configurationContext;
}
public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
MessageContext msgContext = null;
SimpleResponse response = new SimpleResponse();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
if (configurationContext == null) {
throw new AxisFault(Messages.getMessage("cannotBeNullConfigurationContext"));
}
InputStream inStream = request.getBody();
TransportOutDescription transportOut =
configurationContext.getAxisConfiguration().getTransportOut(
new QName(Constants.TRANSPORT_HTTP));
msgContext =
new MessageContext(
configurationContext,
configurationContext.getAxisConfiguration().getTransportIn(
new QName(Constants.TRANSPORT_HTTP)),
transportOut);
msgContext.setServerSide(true);
HttpVersion ver = request.getRequestLine().getHttpVersion();
if (ver == null) {
throw new AxisFault("HTTP version can not be Null");
}
String httpVersion = null;
if (HttpVersion.HTTP_1_0.equals(ver)) {
httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
} else if (HttpVersion.HTTP_1_1.equals(ver)) {
httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
/**
* Transport Sender configuration via axis2.xml
*/
this.transportOutConfiguration(configurationContext,response);
} else {
throw new AxisFault("Unknown supported protocol version " + ver);
}
msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
//set the transport Headers
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, getHeaders(request));
msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
//This is way to provide Accsess to the transport information to the transport Sender
msgContext.setProperty(
HTTPConstants.HTTPOutTransportInfo,
new SimpleHTTPOutTransportInfo(response));
String soapAction = null;
if (request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION) != null) {
soapAction = request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION).getValue();
}
if (HTTPConstants.HEADER_GET.equals(request.getRequestLine().getMethod())) {
//It is GET handle the Get request
boolean processed =
HTTPTransportUtils.processHTTPGetRequest(
msgContext,
inStream,
baos,
request.getContentType(),
soapAction,
request.getRequestLine().getUri(),
configurationContext,
HTTPTransportReceiver.getGetRequestParameters(
request.getRequestLine().getUri()));
if (!processed) {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
response.addHeader(new Header("Content-Type", "text/html"));
response.setBodyString(HTTPTransportReceiver.getServicesHTML(configurationContext));
setResponseHeaders(conn, request, response,0);
conn.writeResponse(response);
return true;
}
} else {
ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
byte[] bytes = new byte[8192];
int size = 0;
while ((size = inStream.read(bytes)) > 0) {
baosIn.write(bytes, 0, size);
}
inStream = new ByteArrayInputStream(baosIn.toByteArray());
//It is POST, handle it
HTTPTransportUtils.processHTTPPostRequest(
msgContext,
inStream,
baos,
request.getContentType(),
soapAction,
request.getRequestLine().getUri(),
configurationContext);
}
OperationContext operationContext = msgContext.getOperationContext();
Object contextWritten = null;
if (operationContext!=null)
contextWritten = operationContext.getProperty(Constants.RESPONSE_WRITTEN);
if (contextWritten != null &&
Constants.VALUE_TRUE.equals(contextWritten)) {
response.setStatusLine(
request.getRequestLine().getHttpVersion(), 200, "OK");
} else {
response.setStatusLine(
request.getRequestLine().getHttpVersion(), 202, "OK");
}
response.setBody(new ByteArrayInputStream(baos.toByteArray()));
setResponseHeaders(conn, request, response,
baos.toByteArray().length);
conn.writeResponse(response);
} catch (Throwable e) {
if(!(e instanceof java.net.SocketException)) {
log.debug(e.getMessage(), e);
}
try {
AxisEngine engine = new AxisEngine(configurationContext);
if (msgContext != null) {
msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
response.setStatusLine(request.getRequestLine().getHttpVersion(), 500, "Internal server error");
engine.sendFault(faultContext);
response.setBody(new ByteArrayInputStream(baos.toByteArray()));
setResponseHeaders(conn, request, response,baos.toByteArray().length);
conn.writeResponse(response);
}
} catch (SocketException e1) {
log.debug(e1.getMessage(), e1);