You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ke...@apache.org on 2007/01/30 05:56:36 UTC
svn commit: r501310 -
/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
Author: keithc
Date: Mon Jan 29 20:56:35 2007
New Revision: 501310
URL: http://svn.apache.org/viewvc?view=rev&rev=501310
Log:
Updated Rest servlet to reflect changes done to AxisServlet
Modified:
webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java?view=diff&rev=501310&r1=501309&r2=501310
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java Mon Jan 29 20:56:35 2007
@@ -16,6 +16,11 @@
package org.apache.axis2.transport.http;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.AxisBindingOperation;
+import org.apache.axis2.description.AxisBindingMessage;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.http.util.RESTUtil;
@@ -28,6 +33,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
/**
*
@@ -40,41 +47,127 @@
HttpServletResponse resp) throws ServletException, IOException {
if (!disableREST && !disableSeperateEndpointForREST) {
MessageContext messageContext = null;
+ OutputStream out = resp.getOutputStream();
try {
messageContext = createMessageContext(req, resp);
+ messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET);
new RESTUtil(configContext).processGetRequest(messageContext,
req,
resp);
- } catch (Exception e) {
- log.error(e);
+ Object contextWritten =
+ messageContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+ if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ }
+ } catch (AxisFault e) {
+ log.debug(e);
if (messageContext != null) {
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
+ processAxisFault(messageContext, resp, out, e);
} else {
throw new ServletException(e);
}
}
+ } else {
+ PrintWriter writer = new PrintWriter(resp.getOutputStream());
+ writer.println("<html><body><h2>Please enable REST support in WEB-INF/conf/axis2.xml and WEB-INF/web.xml</h2></body></html>");
+ writer.flush();
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+
+ initContextRoot(req);
+
+ MessageContext msgContext;
+ OutputStream out = resp.getOutputStream();
if (!disableREST && !disableSeperateEndpointForREST) {
+ msgContext = createMessageContext(req, resp);
+ try {
+
+ new RESTUtil(configContext).processPostRequest(msgContext, req, resp);
+ Object contextWritten =
+ msgContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+ if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ }
+ } catch (AxisFault e) {
+ log.debug(e);
+ if (msgContext != null) {
+ processAxisFault(msgContext, resp, out, e);
+ } else {
+ throw new ServletException(e);
+ }
+ }
+ }
+ }
+
+ protected void doDelete(HttpServletRequest req,
+ HttpServletResponse resp) throws ServletException, IOException {
+
+ initContextRoot(req);
+
+ // this method is also used to serve for the listServices request.
+
+ if (!disableREST && enableRESTInAxis2MainServlet) { // if the main servlet should handle REST also
MessageContext messageContext = null;
+ OutputStream out = resp.getOutputStream();
try {
messageContext = createMessageContext(req, resp);
- new RESTUtil(configContext).processPostRequest(messageContext,
+ messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_DELETE);
+ new RESTUtil(configContext).processGetRequest(messageContext,
req,
resp);
- } catch (Exception e) {
- log.error(e);
+ Object contextWritten =
+ messageContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+ if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ }
+ } catch (AxisFault e) {
+ log.debug(e);
if (messageContext != null) {
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
- } else {
- throw new ServletException(e);
+ processAxisFault(messageContext, resp, out, e);
+ }}
+ } else {
+ PrintWriter writer = new PrintWriter(resp.getOutputStream());
+ writer.println("<html><body><h2>Please enable REST support in WEB-INF/conf/axis2.xml and WEB-INF/web.xml</h2></body></html>");
+ writer.flush();
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ }
+ }
+
+ protected void doPut(HttpServletRequest req,
+ HttpServletResponse resp) throws ServletException, IOException {
+
+ initContextRoot(req);
+
+ // this method is also used to serve for the listServices request.
+
+ if (!disableREST && enableRESTInAxis2MainServlet) { // if the main servlet should handle REST also
+ MessageContext messageContext = null;
+ OutputStream out = resp.getOutputStream();
+ try {
+ messageContext = createMessageContext(req, resp);
+ messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_PUT);
+ new RESTUtil(configContext).processPostRequest(messageContext,
+ req,
+ resp);
+ Object contextWritten =
+ messageContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+ if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten)) {
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
}
- }
+ } catch (AxisFault e) {
+ log.debug(e);
+ if (messageContext != null) {
+ processAxisFault(messageContext, resp, out, e);
+ }}
+ } else {
+ PrintWriter writer = new PrintWriter(resp.getOutputStream());
+ writer.println("<html><body><h2>Please enable REST support in WEB-INF/conf/axis2.xml and WEB-INF/web.xml</h2></body></html>");
+ writer.flush();
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
}
}
@@ -93,6 +186,32 @@
public void init() throws ServletException {
if (this.servletConfig != null) {
init(this.servletConfig);
+ }
+ }
+
+ private void processAxisFault(MessageContext msgContext, HttpServletResponse res, OutputStream out, AxisFault e) {
+ try {
+ // If the fault is not going along the back channel we should be 202ing
+ if (AddressingHelper.isFaultRedirected(msgContext)) {
+ res.setStatus(HttpServletResponse.SC_ACCEPTED);
+ } else {
+
+ res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+ AxisBindingOperation axisBindingOperation = (AxisBindingOperation) msgContext.getProperty(Constants.AXIS_BINDING_OPERATION);
+ if (axisBindingOperation != null) {
+ AxisBindingMessage fault = axisBindingOperation.getFault((String) msgContext.getProperty(Constants.FAULT_NAME));
+ if (fault != null) {
+ Integer code = (Integer) fault.getProperty(WSDL2Constants.ATTR_WHTTP_CODE);
+ if (code != null) {
+ res.setStatus(code.intValue());
+ }
+ }
+ }
+ }
+ handleFault(msgContext, out, e);
+ } catch (AxisFault e2) {
+ log.info(e2);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org