You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/02/13 19:15:46 UTC
svn commit: r744201 - in
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: client/
ext/form/
Author: sergeyb
Date: Fri Feb 13 18:15:45 2009
New Revision: 744201
URL: http://svn.apache.org/viewvc?rev=744201&view=rev
Log:
JAXRS : adding few javadocs to client api classes
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Client.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ResponseExceptionMapper.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/form/Form.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Fri Feb 13 18:15:45 2009
@@ -51,6 +51,10 @@
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.message.MessageImpl;
+/**
+ * Common proxy and http-centric client implementation
+ *
+ */
public class AbstractClient implements Client {
private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String, String>();
@@ -72,6 +76,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public Client header(String name, Object... values) {
if (values == null) {
throw new IllegalArgumentException();
@@ -85,11 +92,17 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client headers(MultivaluedMap<String, String> map) {
requestHeaders.putAll(map);
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client accept(MediaType... types) {
for (MediaType mt : types) {
requestHeaders.add(HttpHeaders.ACCEPT, mt.toString());
@@ -97,15 +110,24 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client type(MediaType ct) {
return type(ct.toString());
}
+ /**
+ * {@inheritDoc}
+ */
public Client type(String type) {
requestHeaders.putSingle(HttpHeaders.CONTENT_TYPE, type);
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client accept(String... types) {
for (String type : types) {
requestHeaders.add(HttpHeaders.ACCEPT, type);
@@ -113,11 +135,17 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client cookie(Cookie cookie) {
requestHeaders.add(HttpHeaders.COOKIE, cookie.toString());
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client modified(Date date, boolean ifNot) {
SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat();
String hName = ifNot ? HttpHeaders.IF_UNMODIFIED_SINCE : HttpHeaders.IF_MODIFIED_SINCE;
@@ -125,17 +153,26 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client language(String language) {
requestHeaders.putSingle(HttpHeaders.CONTENT_LANGUAGE, language);
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client match(EntityTag tag, boolean ifNot) {
String hName = ifNot ? HttpHeaders.IF_NONE_MATCH : HttpHeaders.IF_MATCH;
requestHeaders.putSingle(hName, tag.toString());
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client acceptLanguage(String... languages) {
for (String s : languages) {
requestHeaders.add(HttpHeaders.ACCEPT_LANGUAGE, s);
@@ -143,6 +180,9 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client acceptEncoding(String... encs) {
for (String s : encs) {
requestHeaders.add(HttpHeaders.ACCEPT_ENCODING, s);
@@ -150,46 +190,40 @@
return this;
}
+ /**
+ * {@inheritDoc}
+ */
public Client encoding(String enc) {
requestHeaders.putSingle(HttpHeaders.CONTENT_ENCODING, enc);
return this;
}
-
- protected List<MediaType> getAccept() {
- List<String> headers = requestHeaders.get(HttpHeaders.ACCEPT);
- if (headers == null || headers.size() == 0) {
- return null;
- }
- List<MediaType> types = new ArrayList<MediaType>();
- for (String s : headers) {
- types.add(MediaType.valueOf(s));
- }
- return types;
- }
+ /**
+ * {@inheritDoc}
+ */
public MultivaluedMap<String, String> getHeaders() {
MultivaluedMap<String, String> map = new MetadataMap<String, String>();
map.putAll(requestHeaders);
return map;
}
- protected MediaType getType() {
- String type = requestHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
- return type == null ? null : MediaType.valueOf(type);
- }
-
+ /**
+ * {@inheritDoc}
+ */
public URI getBaseURI() {
return baseURI;
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public URI getCurrentURI() {
return getCurrentBuilder().clone().build();
}
-
- protected UriBuilder getCurrentBuilder() {
- return currentBuilder;
- }
+ /**
+ * {@inheritDoc}
+ */
public Response getResponse() {
if (responseBuilder == null) {
throw new IllegalStateException();
@@ -199,12 +233,38 @@
return r;
}
+ /**
+ * {@inheritDoc}
+ */
public Client reset() {
requestHeaders.clear();
resetResponse();
return this;
}
+
+ protected List<MediaType> getAccept() {
+ List<String> headers = requestHeaders.get(HttpHeaders.ACCEPT);
+ if (headers == null || headers.size() == 0) {
+ return null;
+ }
+ List<MediaType> types = new ArrayList<MediaType>();
+ for (String s : headers) {
+ types.add(MediaType.valueOf(s));
+ }
+ return types;
+ }
+
+
+ protected MediaType getType() {
+ String type = requestHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
+ return type == null ? null : MediaType.valueOf(type);
+ }
+
+ protected UriBuilder getCurrentBuilder() {
+ return currentBuilder;
+ }
+
protected void resetResponse() {
responseBuilder = null;
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Client.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Client.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Client.java Fri Feb 13 18:15:45 2009
@@ -27,32 +27,134 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+/**
+ * Represents common proxy and http-centric client capabilities
+ *
+ */
public interface Client {
+ /**
+ * sets HTTP Content-Type header
+ * @param ct JAXRS MediaType representing Content-Type value
+ * @return the updated Client
+ */
Client type(MediaType ct);
+
+ /**
+ * sets HTTP Content-Type header
+ * @param type Content-Type value
+ * @return the updated Client
+ */
Client type(String type);
+
+ /**
+ * sets HTTP Accept header
+ * @param types list of JAXRS MediaTypes representing Accept header values
+ * @return the updated Client
+ */
Client accept(MediaType... types);
+
+ /**
+ * sets HTTP Accept header
+ * @param types list of Accept header values
+ * @return the updated Client
+ */
Client accept(String... types);
+ /**
+ * sets HTTP Content-Language header
+ * @param language Content-Language header value
+ * @return the updated Client
+ */
Client language(String language);
- Client acceptLanguage(String ...languages);
- Client encoding(String enc);
- Client acceptEncoding(String ...encs);
+ /**
+ * sets HTTP Accept-Language header
+ * @param languages list of Accept-Language header values
+ * @return the updated Client
+ */
+ Client acceptLanguage(String ...languages);
+ /**
+ * sets HTTP Content-Encoding header
+ * @param encoding Content-Encoding header value
+ * @return the updated Client
+ */
+ Client encoding(String encoding);
+
+ /**
+ * sets HTTP Accept-Encoding header
+ * @param encodings list of Accept-Encoding header value
+ * @return the updated Client
+ */
+ Client acceptEncoding(String ...encodings);
+
+ /**
+ * sets HTTP If-Match or If-None-Match header
+ * @param tag ETag value
+ * @param ifNot if true then If-None-Match is set, If-Match otherwise
+ * @return the updated Client
+ */
Client match(EntityTag tag, boolean ifNot);
+
+ /**
+ * sets HTTP If-Modified-Since or If-Unmodified-Since header
+ * @param date Date value, will be formated as "EEE, dd MMM yyyy HH:mm:ss zzz"
+ * @param ifNot if true then If-Unmodified-Since is set, If-Modified-Since otherwise
+ * @return the updated Client
+ */
Client modified(Date date, boolean ifNot);
+ /**
+ * sets HTTP Cookie header
+ * @param cookie Cookie value
+ * @return the updated Client
+ */
Client cookie(Cookie cookie);
+ /**
+ * Sets arbitrary HTTP Header
+ * @param name header name
+ * @param values list of header values
+ * @return the updated Client
+ */
Client header(String name, Object... values);
- Client headers(MultivaluedMap<String, String> map);
+ /**
+ * Sets HTTP Headers
+ * @param map headers
+ * @return the updated Client
+ */
+ Client headers(MultivaluedMap<String, String> map);
+
+ /**
+ * Resets the headers and response state if any
+ * @return the updated Client
+ */
Client reset();
+ /**
+ * Gets the copy of request headers
+ * @return request headers
+ */
MultivaluedMap<String, String> getHeaders();
+
+ /**
+ * Gets the base URI this Client has been intialized with
+ * @return base URI
+ */
URI getBaseURI();
+
+ /**
+ * Gets the current URI this Client is working with
+ * @return current URI
+ */
URI getCurrentURI();
+ /**
+ * Gets the response state if any
+ * @return JAXRS Response response
+ * @throws IllegalStateException if no request has been made or this method called more than once
+ */
Response getResponse();
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Fri Feb 13 18:15:45 2009
@@ -50,6 +50,10 @@
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.jaxrs.utils.ParameterType;
+/**
+ * Proxy-based client implementation
+ *
+ */
public class ClientProxyImpl extends AbstractClient implements InvocationHandler {
private ClassResourceInfo cri;
@@ -61,6 +65,12 @@
this.inheritHeaders = inheritHeaders;
}
+ /**
+ * Updates the current state if Client method is invoked, otherwise
+ * does the remote invocation or returns a new proxy if subresource
+ * method is invoked. Can throw an expected exception if ResponseExceptionMapper
+ * is registered
+ */
public Object invoke(Object o, Method m, Object[] params) throws Throwable {
resetResponse();
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java Fri Feb 13 18:15:45 2009
@@ -28,24 +28,54 @@
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.ResourceUtils;
+/**
+ * Factory for creating proxy clients.
+ *
+ */
public final class JAXRSClientFactory {
private JAXRSClientFactory() {
}
+ /**
+ * Creates a proxy
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @return typed proxy
+ */
public static <T> T create(String baseAddress, Class<T> cls) {
return create(URI.create(baseAddress), cls);
}
+ /**
+ * Creates a proxy
+ * @param baseURI baseURI
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @return typed proxy
+ */
public static <T> T create(URI baseURI, Class<T> cls) {
return create(baseURI, baseURI, cls, true, false);
}
+ /**
+ * Creates a proxy
+ * @param baseURI baseURI
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @return typed proxy
+ */
public static <T> T create(URI baseURI, Class<T> cls, boolean inheritHeaders) {
return create(baseURI, baseURI, cls, true, inheritHeaders);
}
+ /**
+ * Creates a proxy
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param contentType JAXRS MediaType representing HTTP Content-Type header, can be null
+ * @param acceptTypes JAXRS MediaTypes representing HTTP Accept header, can be null
+ * @return typed proxy
+ */
public static <T> T create(String baseAddress, Class<T> cls, MediaType contentType,
MediaType... acceptTypes) {
T proxy = create(baseAddress, cls);
@@ -53,10 +83,24 @@
return proxy;
}
+ /**
+ * Creates a proxy, baseURI will be set to Client currentURI
+ * @param client Client instance
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @return typed proxy
+ */
public static <T> T fromClient(Client client, Class<T> cls) {
return fromClient(client, cls, false);
}
+ /**
+ * Creates a proxy, baseURI will be set to Client currentURI
+ * @param client Client instance
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param inheritHeaders if existing Client headers can be inherited by new proxy
+ * and subresource proxies if any
+ * @return typed proxy
+ */
public static <T> T fromClient(Client client, Class<T> cls, boolean inheritHeaders) {
if (client.getClass().isAssignableFrom(cls)) {
return cls.cast(client);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ResponseExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ResponseExceptionMapper.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ResponseExceptionMapper.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ResponseExceptionMapper.java Fri Feb 13 18:15:45 2009
@@ -20,6 +20,15 @@
import javax.ws.rs.core.Response;
+/**
+ * Converts Response to checked or runtime Exception
+ */
public interface ResponseExceptionMapper<E extends Throwable> {
+
+ /**
+ * Converts Response to checked or runtime Exception
+ * @param r JAXRS Response
+ * @return mapped exception instance, can be null
+ */
E fromResponse(Response r);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Fri Feb 13 18:15:45 2009
@@ -42,95 +42,135 @@
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-
+/**
+ * Http-centric web client
+ *
+ */
public class WebClient extends AbstractClient {
+ /**
+ * Creates WebClient
+ * @param baseAddress baseAddress
+ */
public WebClient(String baseAddress) {
this(URI.create(baseAddress));
}
+ /**
+ * Creates WebClient
+ * @param baseURI baseURI
+ */
public WebClient(URI baseURI) {
super(baseURI, baseURI);
}
+ /**
+ * Creates WebClient, baseURI will be set to Client currentURI
+ * @param client existing client
+ */
public WebClient(Client client) {
this(client, false);
}
+ /**
+ * Creates WebClient, baseURI will be set to Client currentURI
+ * @param client existing client
+ * @param inheritHeaders if existing Client headers can be inherited by new proxy
+ * and subresource proxies if any
+ */
public WebClient(Client client, boolean inheritHeaders) {
super(client, inheritHeaders);
}
+ /**
+ * Does HTTP invocation
+ * @param httpMethod HTTP method
+ * @param body request body, can be null
+ * @return JAXRS Response, entity may hold a string representaion of
+ * error message if client or server error occured
+ */
public Response invoke(String httpMethod, Object body) {
return doInvoke(httpMethod, body, InputStream.class);
}
- private Response doInvoke(String httpMethod, Object body, Class<?> responseClass) {
- HttpURLConnection conn = getConnection(httpMethod);
-
- MultivaluedMap<String, String> headers = getHeaders();
- if (body != null && headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
- headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_TYPE.toString());
- }
- if (responseClass != null && headers.getFirst(HttpHeaders.ACCEPT) == null) {
- headers.putSingle(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_TYPE.toString());
- }
- setAllHeaders(headers, conn);
- if (body != null) {
- try {
- writeBody(body, body.getClass(), body.getClass(),
- new Annotation[]{}, headers, conn.getOutputStream());
- } catch (IOException ex) {
- throw new WebApplicationException(ex);
- }
- }
- try {
- ResponseBuilder rb = setResponseBuilder(conn).clone();
- Response currentResponse = rb.clone().build();
- Object entity = readBody(currentResponse, conn, responseClass, responseClass,
- new Annotation[]{});
- rb.entity(entity);
-
- return rb.build();
- } catch (IOException ex) {
- throw new WebApplicationException(ex);
- }
- }
-
- public Response post(Object o) {
- return invoke("POST", o);
- }
-
- public Response put(Object o) {
- return invoke("PUT", o);
+ /**
+ * Does HTTP POST invocation
+ * @param body request body, can be null
+ * @return JAXRS Response
+ */
+ public Response post(Object body) {
+ return invoke("POST", body);
+ }
+
+ /**
+ * Does HTTP PUT invocation
+ * @param body request body, can be null
+ * @return JAXRS Response
+ */
+ public Response put(Object body) {
+ return invoke("PUT", body);
}
+ /**
+ * Does HTTP GET invocation
+ * @return JAXRS Response
+ */
public Response get() {
return invoke("GET", null);
}
-
+
+ /**
+ * Does HTTP HEAD invocation
+ * @return JAXRS Response
+ */
public Response head() {
return invoke("HEAD", null);
}
-
+
+ /**
+ * Does HTTP OPTIONS invocation
+ * @return JAXRS Response
+ */
public Response options() {
return invoke("OPTIONS", null);
}
-
+
+ /**
+ * Does HTTP DELETE invocation
+ * @return JAXRS Response
+ */
public Response delete() {
return invoke("DELETE", null);
}
-
+
+ /**
+ * Posts form data
+ * @param values form values
+ * @return JAXRS Response
+ */
public Response form(Map<String, List<Object>> values) {
type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
return doInvoke("POST", values, InputStream.class);
}
+ /**
+ * Posts form data
+ * @param form form values
+ * @return JAXRS Response
+ */
public Response form(Form form) {
type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
return doInvoke("POST", form.getData(), InputStream.class);
}
+ /**
+ * Does HTTP invocation and returns types response object
+ * @param httpMethod HTTP method
+ * @param body request body, can be null
+ * @param responseClass expected type of response object
+ * @return typed object, can be null. Response status code and headers
+ * can be obtained too, see Client.getResponse()
+ */
public <T> T invoke(String httpMethod, Object body, Class<T> responseClass) {
Response r = doInvoke(httpMethod, body, responseClass);
@@ -141,29 +181,66 @@
return responseClass.cast(r.getEntity());
}
- public <T> T post(Object o, Class<T> responseClass) {
- return invoke("POST", o, responseClass);
- }
-
+ /**
+ * Does HTTP POST invocation and returns typed response object
+ * @param body request body, can be null
+ * @param responseClass expected type of response object
+ * @return typed object, can be null. Response status code and headers
+ * can be obtained too, see Client.getResponse()
+ */
+ public <T> T post(Object body, Class<T> responseClass) {
+ return invoke("POST", body, responseClass);
+ }
+
+ /**
+ * Does HTTP GET invocation and returns typed response object
+ * @param body request body, can be null
+ * @param responseClass expected type of response object
+ * @return typed object, can be null. Response status code and headers
+ * can be obtained too, see Client.getResponse()
+ */
public <T> T get(Class<T> responseClass) {
return invoke("GET", null, responseClass);
}
+ /**
+ * Updates the current URI path
+ * @param path new relative path segment
+ * @return updated WebClient
+ */
public WebClient path(String path) {
getCurrentBuilder().path(path);
return this;
}
+ /**
+ * Updates the current URI query parameters
+ * @param name query name
+ * @param values query values
+ * @return updated WebClient
+ */
public WebClient query(String name, Object ...values) {
getCurrentBuilder().queryParam(name, values);
return this;
}
+ /**
+ * Updates the current URI matrix parameters
+ * @param name matrix name
+ * @param values matrix values
+ * @return updated WebClient
+ */
public WebClient matrix(String name, Object ...values) {
getCurrentBuilder().matrixParam(name, values);
return this;
}
+ /**
+ * Moves WebClient to a new baseURI or forwards to new currentURI
+ * @param newAddress new URI
+ * @param forward if true then currentURI will be based on baseURI
+ * @return updated WebClient
+ */
public WebClient to(String newAddress, boolean forward) {
if (forward) {
if (!newAddress.startsWith(getBaseURI().toString())) {
@@ -176,6 +253,11 @@
return this;
}
+ /**
+ * Goes back
+ * @param fast if true then goes back to baseURI otherwise to a previous path segment
+ * @return updated WebClient
+ */
public WebClient back(boolean fast) {
if (fast) {
getCurrentBuilder().replacePath(getBaseURI().getPath());
@@ -194,6 +276,15 @@
return this;
}
+ /**
+ * Converts proxy to Client
+ * @param proxy the proxy
+ * @return proxy as a Client
+ */
+ public static Client client(Object proxy) {
+ return (Client)proxy;
+ }
+
@Override
public WebClient type(MediaType ct) {
return (WebClient)super.type(ct);
@@ -264,13 +355,42 @@
return (WebClient)super.reset();
}
+ private Response doInvoke(String httpMethod, Object body, Class<?> responseClass) {
+ HttpURLConnection conn = getConnection(httpMethod);
+
+ MultivaluedMap<String, String> headers = getHeaders();
+ if (body != null && headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
+ headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_TYPE.toString());
+ }
+ if (responseClass != null && headers.getFirst(HttpHeaders.ACCEPT) == null) {
+ headers.putSingle(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_TYPE.toString());
+ }
+ setAllHeaders(headers, conn);
+ if (body != null) {
+ try {
+ writeBody(body, body.getClass(), body.getClass(),
+ new Annotation[]{}, headers, conn.getOutputStream());
+ } catch (IOException ex) {
+ throw new WebApplicationException(ex);
+ }
+ }
+ try {
+ ResponseBuilder rb = setResponseBuilder(conn).clone();
+ Response currentResponse = rb.clone().build();
+ Object entity = readBody(currentResponse, conn, responseClass, responseClass,
+ new Annotation[]{});
+ rb.entity(entity);
+
+ return rb.build();
+ } catch (IOException ex) {
+ throw new WebApplicationException(ex);
+ }
+ }
protected HttpURLConnection getConnection(String methodName) {
return createHttpConnection(getCurrentBuilder().clone().build(), methodName);
}
- public static Client client(Object proxy) {
- return (Client)proxy;
- }
+
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/XMLSource.java Fri Feb 13 18:15:45 2009
@@ -39,6 +39,10 @@
import org.apache.cxf.helpers.CastUtils;
+/**
+ * Utiliity class for manipulating XML response using XPath and XSLT
+ *
+ */
public class XMLSource {
private InputSource source;
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/form/Form.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/form/Form.java?rev=744201&r1=744200&r2=744201&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/form/Form.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/form/Form.java Fri Feb 13 18:15:45 2009
@@ -23,6 +23,10 @@
import org.apache.cxf.jaxrs.impl.MetadataMap;
+/**
+ * Simple MultivaluedMap wrapper
+ *
+ */
public class Form {
private MultivaluedMap<String, Object> map =
new MetadataMap<String, Object>();