You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by az...@apache.org on 2007/05/15 09:27:37 UTC
svn commit: r538077 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2:
Constants.java transport/http/AxisServlet.java
transport/http/server/AxisHttpService.java
Author: azeez
Date: Tue May 15 00:27:37 2007
New Revision: 538077
URL: http://svn.apache.org/viewvc?view=rev&rev=538077
Log:
1. Ability to handle custom states
2. Refactoring
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/AxisHttpService.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=538077&r1=538076&r2=538077
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Tue May 15 00:27:37 2007
@@ -80,6 +80,9 @@
//Parameter name for transport session managemntt
public static final String MANAGE_TRANSPORT_SESSION = "manageTransportSession";
+ public static final String HTTP_RESPONSE_STATE = "axis2.http.response.state";
+ public static final String HTTP_BASIC_AUTH_REALM = "axis2.authentication.realm";
+
/**
* Field APPLICATION_SCOPE
*/
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?view=diff&rev=538077&r1=538076&r2=538077
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java Tue May 15 00:27:37 2007
@@ -27,18 +27,9 @@
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.context.SessionContext;
+import org.apache.axis2.context.*;
import org.apache.axis2.deployment.WarBasedAxisConfigurator;
-import org.apache.axis2.description.AxisBindingMessage;
-import org.apache.axis2.description.AxisBindingOperation;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.description.*;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisEngine;
import org.apache.axis2.engine.Handler.InvocationResponse;
@@ -58,11 +49,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
+import java.io.*;
import java.net.SocketException;
import java.util.Map;
@@ -124,7 +111,7 @@
(Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE);
if (pi.equals(InvocationResponse.SUSPEND) ||
- (holdResponse != null && Boolean.TRUE.equals(holdResponse))) {
+ (holdResponse != null && Boolean.TRUE.equals(holdResponse))) {
((RequestResponseTransport) msgContext
.getProperty(RequestResponseTransport.TRANSPORT_CONTROL))
.awaitResponse();
@@ -138,7 +125,7 @@
}
response.setContentType("text/xml; charset="
- + msgContext
+ + msgContext
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
@@ -146,6 +133,7 @@
}
} catch (AxisFault e) {
+ setResponseState(msgContext, response);
log.debug(e);
if (msgContext != null) {
processAxisFault(msgContext, response, out, e);
@@ -154,42 +142,38 @@
}
} catch (Throwable t) {
log.error(t);
- if (msgContext != null) {
- try {
- // If the fault is not going along the back channel we should be 202ing
- if (AddressingHelper.isFaultRedirected(msgContext)) {
- response.setStatus(HttpServletResponse.SC_ACCEPTED);
- } else {
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-
- AxisBindingOperation axisBindingOperation =
- (AxisBindingOperation) msgContext
- .getProperty(Constants.AXIS_BINDING_OPERATION);
- if (axisBindingOperation != null) {
- Integer code = (Integer) axisBindingOperation.getFault(
- (String) msgContext.getProperty(Constants.FAULT_NAME))
- .getProperty(WSDL2Constants.ATTR_WHTTP_CODE);
- if (code != null) {
- response.setStatus(code.intValue());
- }
+ try {
+ // If the fault is not going along the back channel we should be 202ing
+ if (AddressingHelper.isFaultRedirected(msgContext)) {
+ response.setStatus(HttpServletResponse.SC_ACCEPTED);
+ } else {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+ AxisBindingOperation axisBindingOperation =
+ (AxisBindingOperation) msgContext
+ .getProperty(Constants.AXIS_BINDING_OPERATION);
+ if (axisBindingOperation != null) {
+ Integer code = (Integer) axisBindingOperation.getFault(
+ (String) msgContext.getProperty(Constants.FAULT_NAME))
+ .getProperty(WSDL2Constants.ATTR_WHTTP_CODE);
+ if (code != null) {
+ response.setStatus(code.intValue());
}
}
- handleFault(msgContext, out, new AxisFault(t.toString(), t));
- } catch (AxisFault e2) {
- log.info(e2);
- throw new ServletException(e2);
}
- } else {
- throw new ServletException(t);
+ handleFault(msgContext, out, new AxisFault(t.toString(), t));
+ } catch (AxisFault e2) {
+ log.info(e2);
+ throw new ServletException(e2);
}
closeStaxBuilder(msgContext);
}
} else {
if (!disableREST) {
- new ProcessRESTRequest(Constants.Configuration.HTTP_METHOD_POST, request, response)
+ new RestRequestProcessor(Constants.Configuration.HTTP_METHOD_POST, request, response)
.processXMLRequest();
} else {
- disableRESTErrorMessage(response);
+ showRestDisabledErrorMessage(response);
}
}
}
@@ -218,15 +202,15 @@
// 2. list services requests
// 3. REST requests.
if ((query != null) && (query.indexOf("wsdl2") >= 0 ||
- query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 ||
- query.indexOf("policy") >= 0)) {
+ query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 ||
+ query.indexOf("policy") >= 0)) {
// handling meta data exchange stuff
agent.processListService(request, response);
} else if (requestURI.endsWith(".xsd") ||
- requestURI.endsWith(".wsdl")) {
+ requestURI.endsWith(".wsdl")) {
agent.processExplicitSchemaAndWSDL(request, response);
} else if (requestURI.endsWith(LIST_SERVICES_SUFIX) ||
- requestURI.endsWith(LIST_FAUKT_SERVICES_SUFIX)) {
+ requestURI.endsWith(LIST_FAUKT_SERVICES_SUFIX)) {
// handling list services request
try {
agent.handle(request, response);
@@ -234,10 +218,10 @@
throw new ServletException(e);
}
} else if (!disableREST) {
- new ProcessRESTRequest(Constants.Configuration.HTTP_METHOD_GET, request, response)
+ new RestRequestProcessor(Constants.Configuration.HTTP_METHOD_GET, request, response)
.processURLRequest();
} else {
- disableRESTErrorMessage(response);
+ showRestDisabledErrorMessage(response);
}
}
@@ -256,10 +240,10 @@
initContextRoot(request);
// this method is also used to serve for the listServices request.
if (!disableREST) {
- new ProcessRESTRequest(Constants.Configuration.HTTP_METHOD_DELETE, request, response)
+ new RestRequestProcessor(Constants.Configuration.HTTP_METHOD_DELETE, request, response)
.processURLRequest();
} else {
- disableRESTErrorMessage(response);
+ showRestDisabledErrorMessage(response);
}
}
@@ -277,10 +261,10 @@
initContextRoot(request);
// this method is also used to serve for the listServices request.
if (!disableREST) {
- new ProcessRESTRequest(Constants.Configuration.HTTP_METHOD_PUT, request, response)
+ new RestRequestProcessor(Constants.Configuration.HTTP_METHOD_PUT, request, response)
.processXMLRequest();
} else {
- disableRESTErrorMessage(response);
+ showRestDisabledErrorMessage(response);
}
}
@@ -290,13 +274,12 @@
* @param response
* @throws IOException
*/
- protected void disableRESTErrorMessage(HttpServletResponse response) throws IOException {
+ protected void showRestDisabledErrorMessage(HttpServletResponse response) throws IOException {
PrintWriter writer = new PrintWriter(response.getOutputStream());
writer.println("<html><body><h2>Please enable REST support in WEB-INF/conf/axis2.xml " +
- "and WEB-INF/web.xml</h2></body></html>");
+ "and WEB-INF/web.xml</h2></body></html>");
writer.flush();
response.setStatus(HttpServletResponse.SC_ACCEPTED);
-
}
/**
@@ -336,10 +319,18 @@
res.setStatus(HttpServletResponse.SC_ACCEPTED);
} else {
- res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ String status =
+ (String) msgContext.getOperationContext().
+ getProperty(Constants.HTTP_RESPONSE_STATE);
+ if (status == null) {
+ res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ } else {
+ res.setStatus(Integer.parseInt(status));
+ }
- AxisBindingOperation axisBindingOperation = (AxisBindingOperation) msgContext
- .getProperty(Constants.AXIS_BINDING_OPERATION);
+ AxisBindingOperation axisBindingOperation =
+ (AxisBindingOperation) msgContext
+ .getProperty(Constants.AXIS_BINDING_OPERATION);
if (axisBindingOperation != null) {
AxisBindingMessage fault = axisBindingOperation
.getFault((String) msgContext.getProperty(Constants.FAULT_NAME));
@@ -382,7 +373,7 @@
if (valueElement != null) {
if (valueElement.getText().trim().indexOf(SOAP12Constants.FAULT_CODE_SENDER) >
- -1 && !msgContext.isDoingREST()) {
+ -1 && !msgContext.isDoingREST()) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
@@ -415,8 +406,8 @@
listenerManager.addListener(transportInDescription, true);
listenerManager.start();
ListenerManager.defaultConfigurationContext = configContext;
- agent = new ListingAgent(configContext);
-
+ agent = new ListingAgent(configContext);
+
initParams();
} catch (Exception e) {
@@ -498,7 +489,7 @@
* @param req
*/
public void initContextRoot(HttpServletRequest req) {
- if(contextRoot != null && contextRoot.trim().length() != 0){
+ if (contextRoot != null && contextRoot.trim().length() != 0) {
return;
}
boolean findContext = true;
@@ -563,10 +554,10 @@
EndpointReference endpoint = new EndpointReference("http://" + ip + ":" + port + '/' +
- configContext
- .getServiceContextPath() +
- "/" +
- serviceName);
+ configContext
+ .getServiceContextPath() +
+ "/" +
+ serviceName);
return new EndpointReference[]{endpoint};
}
@@ -638,10 +629,10 @@
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST, request);
msgContext.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, response);
- //setting the RequestResponseTransport object
+ //setting the RequestResponseTransport object
msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL,
- new ServletRequestResponseTransport(response));
-
+ new ServletRequestResponseTransport(response));
+
return msgContext;
}
@@ -688,7 +679,7 @@
private CountDownLatch responseReadySignal = new CountDownLatch(1);
RequestResponseTransportStatus status = RequestResponseTransportStatus.INITIAL;
AxisFault faultToBeThrownOut = null;
-
+
ServletRequestResponseTransport(HttpServletResponse response) {
this.response = response;
}
@@ -696,7 +687,7 @@
public void acknowledgeMessage(MessageContext msgContext) throws AxisFault {
log.debug("Acking one-way request");
response.setContentType("text/xml; charset="
- + msgContext
+ + msgContext
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
response.setStatus(HttpServletResponse.SC_ACCEPTED);
@@ -711,13 +702,14 @@
}
public void awaitResponse()
- throws InterruptedException,AxisFault {
+ throws InterruptedException, AxisFault {
log.debug("Blocking servlet thread -- awaiting response");
status = RequestResponseTransportStatus.WAITING;
responseReadySignal.await();
-
- if (faultToBeThrownOut!=null)
- throw faultToBeThrownOut;
+
+ if (faultToBeThrownOut != null) {
+ throw faultToBeThrownOut;
+ }
}
public void signalResponseReady() {
@@ -730,32 +722,42 @@
return status;
}
- public void signalFaultReady(AxisFault fault) {
- faultToBeThrownOut = fault;
- signalResponseReady();
- }
-
+ public void signalFaultReady(AxisFault fault) {
+ faultToBeThrownOut = fault;
+ signalResponseReady();
+ }
+ }
+
+ private void setResponseState(MessageContext messageContext, HttpServletResponse response) {
+ OperationContext opCtx = messageContext.getOperationContext();
+ String state = (String) opCtx.getProperty(Constants.HTTP_RESPONSE_STATE);
+ if (state != null) {
+ int stateInt = Integer.parseInt(state);
+ if (stateInt == HttpServletResponse.SC_UNAUTHORIZED) { // Unauthorized
+ String realm = (String) opCtx.getProperty(Constants.HTTP_BASIC_AUTH_REALM);
+ response.addHeader("WWW-Authenticate",
+ "basic realm=\"" + realm + "\"");
+ }
+ }
}
/**
* Ues in processing REST related Requests.
* This is the helper Class use in processing of doGet, doPut , doDelete and doPost.
*/
- public class ProcessRESTRequest {
- MessageContext messageContext;
- HttpServletRequest request;
- HttpServletResponse response;
-
- public ProcessRESTRequest(String httpMethodString, HttpServletRequest request,
- HttpServletResponse response)
- throws IOException {
+ protected class RestRequestProcessor {
+ private MessageContext messageContext;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+ public RestRequestProcessor(String httpMethodString,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
this.request = request;
this.response = response;
messageContext = createMessageContext(this.request, this.response, false);
messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD,
httpMethodString);
-
-
}
public void processXMLRequest() throws IOException, ServletException {
@@ -767,8 +769,6 @@
processFault(axisFault);
}
closeStaxBuilder(messageContext);
-
-
}
public void processURLRequest() throws IOException, ServletException {
@@ -776,19 +776,22 @@
RESTUtil.processURLRequest(messageContext, response.getOutputStream(),
request.getContentType());
this.checkResponseWritten();
- } catch (AxisFault axisFault) {
- processFault(axisFault);
+ } catch (AxisFault e) {
+ setResponseState(messageContext, response);
+ processFault(e);
}
closeStaxBuilder(messageContext);
}
private void checkResponseWritten() {
- Object contextWritten =
- messageContext.getOperationContext()
- .getProperty(Constants.RESPONSE_WRITTEN);
- if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
- response.setStatus(HttpServletResponse.SC_ACCEPTED);
+ OperationContext operationContext = messageContext.getOperationContext();
+ if (operationContext != null) {
+ Object contextWritten =
+ operationContext.getProperty(Constants.RESPONSE_WRITTEN);
+ if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ response.setStatus(HttpServletResponse.SC_ACCEPTED);
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/AxisHttpService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/AxisHttpService.java?view=diff&rev=538077&r1=538076&r2=538077
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/AxisHttpService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/AxisHttpService.java Tue May 15 00:27:37 2007
@@ -27,19 +27,14 @@
*/
package org.apache.axis2.transport.http.server;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.SocketException;
-import java.util.HashMap;
-import java.util.Iterator;
-
+import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisEngine;
@@ -48,24 +43,18 @@
import org.apache.axis2.util.MessageContextBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.Header;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
-import org.apache.http.HttpInetConnection;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
-import org.apache.http.MethodNotSupportedException;
-import org.apache.http.ProtocolException;
-import org.apache.http.UnsupportedHttpVersionException;
+import org.apache.http.*;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
-import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.SocketException;
+import java.util.HashMap;
+import java.util.Iterator;
/**
* This class is an extension of the defaulf HTTP service responsible for
@@ -117,30 +106,30 @@
public HttpParams getParams() {
return this.params;
}
-
+
public void setParams(final HttpParams params) {
this.params = params;
}
-
- public void handleRequest(final AxisHttpConnection conn, final HttpContext context)
- throws IOException, HttpException {
-
+
+ public void handleRequest(final AxisHttpConnection conn, final HttpContext context)
+ throws IOException, HttpException {
+
MessageContext msgContext = configurationContext.createMessageContext();
msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
if (conn instanceof HttpInetConnection) {
HttpInetConnection inetconn = (HttpInetConnection) conn;
msgContext.setProperty(MessageContext.REMOTE_ADDR,
- inetconn.getRemoteAddress().getHostAddress());
+ inetconn.getRemoteAddress().getHostAddress());
msgContext.setProperty(MessageContext.TRANSPORT_ADDR,
- inetconn.getLocalAddress().getHostAddress());
+ inetconn.getLocalAddress().getHostAddress());
if (LOG.isDebugEnabled()) {
- LOG.debug("Remote address of the connection : " +
- inetconn.getRemoteAddress().getHostAddress());
+ LOG.debug("Remote address of the connection : " +
+ inetconn.getRemoteAddress().getHostAddress());
}
}
-
+
HttpResponse response;
try {
HttpRequest request = conn.receiveRequest(this.params);
@@ -151,37 +140,37 @@
}
response = this.responseFactory.newHttpResponse
- (ver, HttpStatus.SC_OK, context);
+ (ver, HttpStatus.SC_OK, context);
response.getParams().setDefaults(this.params);
-
+
if (request instanceof HttpEntityEnclosingRequest) {
if (((HttpEntityEnclosingRequest) request).expectContinue()) {
HttpResponse ack = this.responseFactory.newHttpResponse
- (ver, HttpStatus.SC_CONTINUE, context);
+ (ver, HttpStatus.SC_CONTINUE, context);
ack.getParams().setDefaults(this.params);
conn.sendResponse(ack);
conn.flush();
}
}
-
+
// Create Axis request and response objects
AxisHttpRequestImpl axisreq = new AxisHttpRequestImpl(
- conn,
- request,
- this.httpProcessor,
- context);
+ conn,
+ request,
+ this.httpProcessor,
+ context);
AxisHttpResponseImpl axisres = new AxisHttpResponseImpl(
- conn,
- response,
- this.httpProcessor,
- context);
+ conn,
+ response,
+ this.httpProcessor,
+ context);
// Prepare HTTP request
axisreq.prepare();
-
+
// Run the service
doService(axisreq, axisres, context, msgContext);
-
+
// Make sure the request content is fully consumed
InputStream instream = conn.getInputStream();
if (instream != null) {
@@ -198,25 +187,25 @@
if (outstream != null) {
outstream.close();
}
-
+
} catch (HttpException ex) {
response = this.responseFactory.newHttpResponse
- (HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR,
- context);
+ (HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ context);
response.getParams().setDefaults(this.params);
handleException(ex, response);
this.httpProcessor.process(response, context);
conn.sendResponse(response);
}
-
+
conn.flush();
if (!this.connStrategy.keepAlive(response, context)) {
conn.close();
} else {
conn.reset();
}
- }
-
+ }
+
protected void handleException(final HttpException ex, final HttpResponse response) {
if (ex instanceof MethodNotSupportedException) {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
@@ -228,9 +217,9 @@
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
-
+
protected void doService(
- final AxisHttpRequest request,
+ final AxisHttpRequest request,
final AxisHttpResponse response,
final HttpContext context,
final MessageContext msgContext) throws HttpException, IOException {
@@ -251,7 +240,7 @@
msgContext.setServerSide(true);
msgContext.setProperty(HTTPConstants.COOKIE_STRING, sessionKey);
msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL,
- request.getRequestURI());
+ request.getRequestURI());
// set the transport Headers
HashMap headerMap = new HashMap();
@@ -260,18 +249,18 @@
headerMap.put(header.getName(), header.getValue());
}
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,
- headerMap);
+ headerMap);
msgContext.setProperty(Constants.Configuration.CONTENT_TYPE,
- request.getContentType());
-
+ request.getContentType());
+
msgContext.setProperty(MessageContext.TRANSPORT_OUT,
- response.getOutputStream());
+ response.getOutputStream());
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
- response);
+ response);
msgContext.setTo(new EndpointReference(request.getRequestURI()));
msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL,
- new SimpleHTTPRequestResponseTransport());
-
+ new SimpleHTTPRequestResponseTransport());
+
this.worker.service(request, response, msgContext);
} catch (SocketException ex) {
// Socket is unreliable.
@@ -284,9 +273,9 @@
AxisEngine engine = new AxisEngine(this.configurationContext);
msgContext.setProperty(MessageContext.TRANSPORT_OUT,
- response.getOutputStream());
+ response.getOutputStream());
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
- response);
+ response);
MessageContext faultContext =
MessageContextBuilder.createFaultMessageContext(msgContext, e);
@@ -294,11 +283,22 @@
if (AddressingHelper.isFaultRedirected(msgContext)) {
response.setStatus(HttpStatus.SC_ACCEPTED);
} else {
- response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal server error");
+ OperationContext opCtx = msgContext.getOperationContext();
+ String state = (String) opCtx.getProperty(Constants.HTTP_RESPONSE_STATE);
+ if (state != null) {
+ int stateInt = Integer.parseInt(state);
+ response.setStatus(stateInt);
+ if (stateInt == HttpServletResponse.SC_UNAUTHORIZED) { // Unauthorized
+ String realm = (String) opCtx.getProperty(Constants.HTTP_BASIC_AUTH_REALM);
+ response.addHeader("WWW-Authenticate",
+ "basic realm=\"" + realm + "\"");
+ }
+ } else {
+ response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal server error");
+ }
}
engine.sendFault(faultContext);
}
-
}
class SimpleHTTPRequestResponseTransport implements RequestResponseTransport {
@@ -316,8 +316,9 @@
status = RequestResponseTransportStatus.WAITING;
responseReadySignal.await();
- if (faultToBeThrownOut != null)
+ if (faultToBeThrownOut != null) {
throw faultToBeThrownOut;
+ }
}
public void signalResponseReady() {
@@ -335,5 +336,5 @@
}
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org