Author: sergeyb
Date: Mon Dec 6 17:22:07 2010
New Revision: 1042728
URL: http://svn.apache.org/viewvc?rev=1042728&view=rev
Log:
Merged revisions 1042724 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1042724 | sergeyb | 2010-12-06 17:10:01 +0000 (Mon, 06 Dec 2010) | 1 line
[CXF-3150] Introducing ServerWebApplicationException and
ClientWebApplicationException
........
Added:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientWebApplicationException.java
- copied unchanged from r1042724,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientWebApplicationException.java
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java
- copied unchanged from r1042724,
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java
Modified:
cxf/branches/2.3.x-fixes/ (props changed)
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec 6 17:22:07 2010
@@ -1 +1 @@
-/cxf/trunk:1041183,1041790,1041993,1042346,1042571
+/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1042728&r1=1042727&r2=1042728&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Mon Dec 6 17:22:07 2010
@@ -37,7 +37,6 @@ import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
@@ -315,7 +314,8 @@ public class AbstractClient implements C
protected ResponseBuilder setResponseBuilder(HttpURLConnection conn,
Exchange exchange) throws Throwable {
Message inMessage = exchange.getInMessage();
if (conn == null) {
- throw new WebApplicationException();
+ // unlikely to occur
+ throw new ClientWebApplicationException("HTTP Connection is
null");
}
Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
if (responseCode == null) {
@@ -403,11 +403,10 @@ public class AbstractClient implements C
os.flush();
}
} catch (Exception ex) {
- throw new WebApplicationException(ex);
+ reportMessageHandlerProblem("MSG_WRITER_PROBLEM", cls,
contentType, ex, null);
}
-
} else {
- reportNoMessageHandler("NO_MSG_WRITER", cls, contentType);
+ reportMessageHandlerProblem("NO_MSG_WRITER", cls, contentType,
null, null);
}
}
@@ -426,7 +425,7 @@ public class AbstractClient implements C
Object length =
r.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH);
if (length == null || Integer.parseInt(length.toString()) == 0
|| status >= 400) {
- return cls == Response.class ? r : cls ==
InputStream.class ? inputStream : null;
+ return cls == Response.class ? r : inputStream;
}
}
} catch (IOException ex) {
@@ -446,13 +445,12 @@ public class AbstractClient implements C
return mbr.readFrom(cls, type, anns, contentType,
new MetadataMap<String, Object>(r.getMetadata(), true,
true), inputStream);
} catch (Exception ex) {
- throw new WebApplicationException(ex);
+ reportMessageHandlerProblem("MSG_READER_PROBLEM", cls,
contentType, ex, r);
}
-
} else if (cls == Response.class) {
return r;
} else {
- reportNoMessageHandler("NO_MSG_READER", cls, contentType);
+ reportMessageHandlerProblem("NO_MSG_READER", cls, contentType,
null, null);
}
return null;
}
@@ -497,14 +495,15 @@ public class AbstractClient implements C
}
}
- protected static void reportNoMessageHandler(String name, Class<?> cls,
MediaType ct) {
+ protected static void reportMessageHandlerProblem(String name, Class<?>
cls, MediaType ct,
+ Throwable cause,
Response response) {
org.apache.cxf.common.i18n.Message errorMsg =
new org.apache.cxf.common.i18n.Message(name,
BUNDLE,
cls,
ct.toString());
LOG.severe(errorMsg.toString());
- throw new WebApplicationException(415);
+ throw new ClientWebApplicationException(errorMsg.toString(), cause,
response);
}
private static MediaType getResponseContentType(Response r) {
@@ -523,7 +522,7 @@ public class AbstractClient implements C
connect.setRequestMethod(methodName);
return connect;
} catch (Exception ex) {
- throw new WebApplicationException(ex);
+ throw new
ClientWebApplicationException("REMOTE_CONNECTION_PROBLEM", ex, null);
}
}
Modified:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1042728&r1=1042727&r2=1042728&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Mon Dec 6 17:22:07 2010
@@ -35,7 +35,6 @@ import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -230,7 +229,7 @@ public class ClientProxyImpl extends Abs
}
if (t == null) {
- t = new WebApplicationException(r);
+ t = new ServerWebApplicationException(r);
}
@@ -475,7 +474,7 @@ public class ClientProxyImpl extends Abs
m.getDeclaringClass().getName(),
m.getName());
LOG.severe(errorMsg.toString());
- throw new WebApplicationException(405);
+ throw new ClientWebApplicationException(errorMsg.toString());
}
// TODO : what we really need to do is to refactor JAXRSOutInterceptor so
that
Modified:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties?rev=1042728&r1=1042727&r2=1042728&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
(original)
+++
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
Mon Dec 6 17:22:07 2010
@@ -25,4 +25,7 @@ ONLY_FORM_ALLOWED=Resource method {0}.{1
NO_BODY_IN_SUBRESOURCE=SubResource method {0}.{1} expects request body, only
URI-bound parameters are supported
NO_CONTEXT_PARAMETERS=Resource method {0}.{1} expects JAXRS Context parameter
which is not supported on the client side
NO_MSG_READER =.No message body reader found for class : {0}, ContentType :
{1}.
+MSG_READER_PROBLEM =.Problem with reading the response message, class : {0},
ContentType : {1}.
NO_MSG_WRITER =.No message body writer found for class : {0}.
+MSG_WRITER_PROBLEM =.Problem with writing the request message, class : {0}.
+REMOTE_CONNECTION_PROBLEM=Problem with creating a remote connection
\ No newline at end of file
Modified:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1042728&r1=1042727&r2=1042728&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Mon Dec 6 17:22:07 2010
@@ -31,7 +31,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
@@ -325,7 +324,7 @@ public class WebClient extends AbstractC
Response r = doInvoke(httpMethod, body, responseClass, responseClass);
if (r.getStatus() >= 400 && responseClass != null) {
- throw new WebApplicationException(r);
+ throw new ServerWebApplicationException(r);
}
return responseClass.cast(r.getEntity());
@@ -344,7 +343,7 @@ public class WebClient extends AbstractC
new ParameterizedCollectionType<T>(memberClass));
if (r.getStatus() >= 400) {
- throw new WebApplicationException(r);
+ throw new ServerWebApplicationException(r);
}
return CastUtils.cast((Collection)r.getEntity(), memberClass);
@@ -625,7 +624,7 @@ public class WebClient extends AbstractC
HttpURLConnection connect =
(HttpURLConnection)m.get(HTTPConduit.KEY_HTTP_CONNECTION);
if (connect == null && primaryError != null) {
/** do we have a pre-connect error ? */
- throw new WebApplicationException(primaryError);
+ throw new ClientWebApplicationException(primaryError);
}
return handleResponse(connect, m, responseClass, genericType);
}
@@ -642,7 +641,7 @@ public class WebClient extends AbstractC
return rb.build();
} catch (Throwable ex) {
- throw new WebApplicationException(ex);
+ throw new ClientWebApplicationException(ex);
}
}
Modified:
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1042728&r1=1042727&r2=1042728&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Dec 6 17:22:07 2010
@@ -45,6 +45,7 @@ import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.ext.xml.XMLSource;
import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
@@ -168,6 +169,33 @@ public class JAXRSClientServerBookTest e
}
@Test
+ public void testServerWebApplicationException() throws Exception {
+ WebClient wc = WebClient.create("http://localhost:" + PORT +
"/bookstore/webappexception");
+ wc.accept("application/xml");
+ try {
+ wc.get(Book.class);
+ fail("Exception expected");
+ } catch (ServerWebApplicationException ex) {
+ assertEquals(500, ex.getStatus());
+ assertEquals("This is a WebApplicationException", ex.getMessage());
+ assertTrue(ex.toString().contains("This is a
WebApplicationException"));
+ }
+ }
+
+ @Test
+ public void testServerWebApplicationExceptionWithProxy() throws Exception {
+ BookStore store = JAXRSClientFactory.create("http://localhost:" +
PORT, BookStore.class);
+ try {
+ store.throwException();
+ fail("Exception expected");
+ } catch (ServerWebApplicationException ex) {
+ assertEquals(500, ex.getStatus());
+ assertEquals("This is a WebApplicationException", ex.getMessage());
+ assertTrue(ex.toString().contains("This is a
WebApplicationException"));
+ }
+ }
+
+ @Test
public void testWebApplicationException() throws Exception {
getAndCompare("http://localhost:" + PORT +
"/bookstore/webappexception",
"This is a WebApplicationException",