Author: richard.opalka(a)jboss.com
Date: 2009-10-02 08:33:14 -0400 (Fri, 02 Oct 2009)
New Revision: 10828
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandler.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Iface.java
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java
Log:
[JBWS-2674][JBWS-2754] providing exceptions test case (WIP)
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandler.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandler.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandler.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -33,6 +33,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
+import org.jboss.ws.core.jaxws.handler.MessageContextJAXWS;
import org.jboss.ws.extensions.wsrm.transport.backchannel.RMCallbackHandlerImpl;
import org.jboss.wsf.common.ObjectNameFactory;
import org.jboss.wsf.common.injection.InjectionHelper;
@@ -102,22 +103,34 @@
}
}
- public void handle(String method, InputStream inputStream, OutputStream outputStream,
Map<String, Object> requestHeaders) throws IOException
+ public int handle(String method, InputStream inputStream, OutputStream outputStream,
Map<String, Object> requestHeaders) throws IOException
{
- InvocationContext invCtx = new InvocationContext();
- invCtx.addAttachment(Map.class, requestHeaders);
- if (method.equals("POST"))
+ Integer statusCode = null;
+ try
{
- doPost(inputStream, outputStream, invCtx);
+ InvocationContext invCtx = new InvocationContext();
+ invCtx.addAttachment(Map.class, requestHeaders);
+ if (method.equals("POST"))
+ {
+ doPost(inputStream, outputStream, invCtx);
+ statusCode = invCtx.getAttachment(Integer.class);
+ }
+ else if (method.equals("GET"))
+ {
+ doGet(inputStream, outputStream, invCtx);
+ }
+ else
+ {
+ throw new WSException("Unsupported HTTP method: " + method);
+ }
}
- else if (method.equals("GET"))
+ catch(Exception e)
{
- doGet(inputStream, outputStream, invCtx);
+ logger.error(e.getMessage(), e);
+ statusCode = 500;
}
- else
- {
- throw new WSException("Unsupported method: " + method);
- }
+
+ return statusCode == null ? 200 : statusCode;
}
public final String getHandledPath()
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -95,7 +95,8 @@
ChannelBuffer content = request.getContent();
OutputStream baos = new ByteArrayOutputStream();
OutputStream outputStream = new BufferedOutputStream(baos);
-
+ Integer statusCode = null;
+
Map<String, Object> requestHeaders = new HashMap<String, Object>();
for (String headerName : request.getHeaderNames())
{
@@ -111,16 +112,16 @@
requestPath = requestPath.substring(0, paramIndex);
}
String httpMethod = request.getMethod().getName();
- handle(requestPath, httpMethod, getInputStream(content), outputStream,
requestHeaders);
+ statusCode = handle(requestPath, httpMethod, getInputStream(content),
outputStream, requestHeaders);
}
catch (Throwable t)
{
- error = true;
+ statusCode = 500;
LOG.error(t);
}
finally
{
- writeResponse(e, request, error, baos.toString());
+ writeResponse(e, request, baos.toString(), statusCode);
}
}
@@ -129,7 +130,7 @@
return new ChannelBufferInputStream(content);
}
- private void handle(String requestPath, String httpMethod, InputStream inputStream,
OutputStream outputStream, Map<String, Object> requestHeaders) throws IOException
+ private int handle(String requestPath, String httpMethod, InputStream inputStream,
OutputStream outputStream, Map<String, Object> requestHeaders) throws IOException
{
boolean handlerExists = false;
String handledPath = null;
@@ -147,12 +148,13 @@
handlerExists = true;
if (LOG.isDebugEnabled())
LOG.debug("Handling request path: " + requestPath);
- handler.handle(httpMethod, inputStream, outputStream, requestHeaders);
- break;
+ return handler.handle(httpMethod, inputStream, outputStream,
requestHeaders);
}
}
if (handlerExists == false)
LOG.warn("No callback handler registered for path: " + requestPath);
+
+ return 500;
}
private String truncateHostName(String s)
@@ -177,16 +179,14 @@
return retVal;
}
- private void writeResponse(MessageEvent e, HttpRequest request, boolean error, String
content)
+ private void writeResponse(MessageEvent e, HttpRequest request, String content,
Integer statusCode)
{
// Build the response object.
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, error ?
HttpResponseStatus.INTERNAL_SERVER_ERROR : HttpResponseStatus.OK);
+ HttpResponseStatus status = statusCode == 500 ?
HttpResponseStatus.INTERNAL_SERVER_ERROR : HttpResponseStatus.OK;
+ HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/xml;
charset=UTF-8");
- if (!error)
- {
- response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
String.valueOf(content.length()));
- response.setContent(ChannelBuffers.copiedBuffer(content, "UTF-8"));
- }
+ response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
String.valueOf(content.length()));
+ response.setContent(ChannelBuffers.copiedBuffer(content, "UTF-8"));
String cookieString = request.getHeader(HttpHeaders.Names.COOKIE);
if (cookieString != null)
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -320,9 +320,13 @@
// by a null envelope.
SOAPEnvelope soapEnv = part.getEnvelope();
isFault = soapEnv != null && soapEnv.getBody().hasFault();
- if (httpResponse != null && isFault)
+ if (isFault)
{
- httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ invContext.addAttachment(Integer.class,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ if (httpResponse != null)
+ {
+ httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
}
}
Modified:
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java
===================================================================
---
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -101,13 +101,18 @@
endpoint1.stop();
endpoint2.stop();
}
-
- /*
+
public void testEndpointException() throws Exception
{
- // TODO: provide test case where endpoint throws exception
+ String publishURL = "http://" + getServerHost() + ":" + port1 +
"/jaxws-endpoint/endpoint/number1";
+ Endpoint endpoint = publishEndpoint(Endpoint1Impl.class, publishURL);
+
+ invokeEndpoint3(publishURL);
+
+ endpoint.stop();
}
-
+
+ /*
public void testAttachments() throws Exception
{
// TODO: provide test case where client sends attachment
@@ -123,22 +128,16 @@
private void invokeEndpoint1(String publishURL) throws Exception
{
- URL wsdlURL = new URL(publishURL + "?wsdl");
- QName qname = new
QName("http://org.jboss.ws/jaxws/endpoint/jse/endpoints/",
"Endpoint1Impl");
- Service service = Service.create(wsdlURL, qname);
- Endpoint1Iface port = (Endpoint1Iface)service.getPort(Endpoint1Iface.class);
+ Endpoint1Iface port = this.getProxy(publishURL);
String helloWorld = "Hello world!";
Object retObj = port.echo(helloWorld);
assertEquals(helloWorld, retObj);
}
-
+
private void invokeEndpoint2(String publishURL) throws Exception
{
- URL wsdlURL = new URL(publishURL + "?wsdl");
- QName qname = new
QName("http://org.jboss.ws/jaxws/endpoint/jse/endpoints/",
"Endpoint1Impl");
- Service service = Service.create(wsdlURL, qname);
- Endpoint1Iface port = (Endpoint1Iface)service.getPort(Endpoint1Iface.class);
+ Endpoint1Iface port = this.getProxy(publishURL);
// Invoke the endpoint
String helloWorld = "Hello world!";
@@ -150,4 +149,27 @@
assertEquals(2, port.getCount());
}
+ private void invokeEndpoint3(String publishURL) throws Exception
+ {
+ Endpoint1Iface port = this.getProxy(publishURL);
+
+ try
+ {
+ port.getException();
+ fail("Failure expected");
+ }
+ catch (Exception e)
+ {
+ log.debug(e.getMessage());
+ }
+ }
+
+ private Endpoint1Iface getProxy(String publishURL) throws Exception
+ {
+ URL wsdlURL = new URL(publishURL + "?wsdl");
+ QName qname = new
QName("http://org.jboss.ws/jaxws/endpoint/jse/endpoints/",
"Endpoint1Impl");
+ Service service = Service.create(wsdlURL, qname);
+ return (Endpoint1Iface)service.getPort(Endpoint1Iface.class);
+ }
+
}
Modified:
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Iface.java
===================================================================
---
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Iface.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Iface.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -35,4 +35,5 @@
{
String echo(String input);
int getCount();
+ void getException();
}
Modified:
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java
===================================================================
---
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java 2009-10-02
12:06:13 UTC (rev 10827)
+++
stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java 2009-10-02
12:33:14 UTC (rev 10828)
@@ -22,6 +22,7 @@
package org.jboss.test.ws.jaxws.endpoint.jse.endpoints;
import javax.jws.WebService;
+import javax.xml.ws.WebServiceException;
/**
* Service implementation.
@@ -49,5 +50,10 @@
{
return count;
}
+
+ public void getException()
+ {
+ throw new WebServiceException("Ooops");
+ }
}