Author: alessio.soldano(a)jboss.com
Date: 2010-09-05 17:43:40 -0400 (Sun, 05 Sep 2010)
New Revision: 394
Added:
core/trunk/core-cxf/
core/trunk/core-cxf/pom.xml
core/trunk/core-cxf/src/
core/trunk/core-cxf/src/main/
core/trunk/core-cxf/src/main/java/
core/trunk/core-cxf/src/main/java/org/
core/trunk/core-cxf/src/main/java/org/jboss/
core/trunk/core-cxf/src/main/java/org/jboss/wise/
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/CXFRSDynamicClientBuilder.java
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
core/trunk/core-cxf/src/main/resources/
core/trunk/core-cxf/src/main/resources/META-INF/
core/trunk/core-cxf/src/main/resources/META-INF/services/
core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.core.client.builder.RSDynamicClientBuilder
core/trunk/core-cxf/src/test/
core/trunk/core-cxf/src/test/java/
core/trunk/core-cxf/src/test/java/org/
core/trunk/core-cxf/src/test/java/org/jboss/
core/trunk/core-cxf/src/test/java/org/jboss/wise/
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java
core/trunk/core-cxf/src/test/resources/
core/trunk/core-cxf/src/test/resources/jaxrs/
core/trunk/core-cxf/src/test/resources/jaxrs/add_book.txt
core/trunk/core-cxf/src/test/resources/jaxrs/expected_add_book.txt
core/trunk/core-cxf/src/test/resources/jaxrs/expected_get_book123.txt
core/trunk/core-cxf/src/test/resources/jaxrs/expected_update_book.txt
core/trunk/core-cxf/src/test/resources/jaxrs/update_book.txt
core/trunk/core/src/main/java/org/jboss/wise/core/client/builder/RSDynamicClientBuilder.java
Removed:
core/trunk/core/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java
core/trunk/core/src/test/resources/jaxrs/add_book.txt
core/trunk/core/src/test/resources/jaxrs/expected_add_book.txt
core/trunk/core/src/test/resources/jaxrs/expected_get_book123.txt
core/trunk/core/src/test/resources/jaxrs/expected_update_book.txt
core/trunk/core/src/test/resources/jaxrs/update_book.txt
Modified:
core/trunk/core/pom.xml
core/trunk/core/src/main/java/org/jboss/wise/core/client/factories/WSDynamicClientFactory.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WSDLResolver.java
core/trunk/core/src/main/java/org/jboss/wise/core/wsextensions/impl/WSSecurityEnabler.java
core/trunk/pom.xml
Log:
[WISE-169] Adding core-cxf module and moving jaxrs impl stuff there
Modified: core/trunk/core/pom.xml
===================================================================
--- core/trunk/core/pom.xml 2010-09-04 17:28:37 UTC (rev 393)
+++ core/trunk/core/pom.xml 2010-09-05 21:43:40 UTC (rev 394)
@@ -156,51 +156,6 @@
</dependency>
<dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxws</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http-jetty</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxrs</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-parser</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-extensions-json</artifactId>
- </exclusion>
-
- </exclusions>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-testutils</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/builder/RSDynamicClientBuilder.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/builder/RSDynamicClientBuilder.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/builder/RSDynamicClientBuilder.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site:
http://www.fsf.org.
+ */
+
+package org.jboss.wise.core.client.builder;
+
+import java.net.ConnectException;
+
+import net.jcip.annotations.ThreadSafe;
+
+import org.jboss.wise.core.client.WSDynamicClient;
+import org.jboss.wise.core.client.jaxrs.RSDynamicClient;
+import org.jboss.wise.core.client.jaxrs.RSDynamicClient.HttpMethod;
+import org.jboss.wise.core.exception.WiseRuntimeException;
+
+/**
+ *
+ *
+ * @author alessio.soldano(a)jboss.com
+ */
+@ThreadSafe
+public interface RSDynamicClientBuilder {
+
+ /**
+ * Build the {@link WSDynamicClient} with all parameters set on this class
+ *
+ * @return {@link WSDynamicClient}
+ * @throws IllegalStateException
+ * @throws ConnectException
+ * @throws WiseRuntimeException
+ */
+ public RSDynamicClient build() throws IllegalStateException, WiseRuntimeException;
+
+ public RSDynamicClientBuilder resourceURI(String resourceURI);
+
+ public RSDynamicClientBuilder httpMethod(HttpMethod httpMethod);
+
+ public RSDynamicClientBuilder produceMediaTypes(String produceMediaTypes);
+
+ public RSDynamicClientBuilder consumeMediaTypes(String consumeMediaTypes);
+
+ public String getResourceURI();
+
+ public String getProduceMediaTypes();
+
+ public String getConsumeMediaTypes();
+
+ public HttpMethod getHttpMethod();
+
+}
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/factories/WSDynamicClientFactory.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/factories/WSDynamicClientFactory.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/factories/WSDynamicClientFactory.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -23,17 +23,18 @@
package org.jboss.wise.core.client.factories;
import java.net.URL;
+
import net.jcip.annotations.ThreadSafe;
+
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.NullEnumeration;
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.wise.core.client.SpiLoader;
+import org.jboss.wise.core.client.builder.RSDynamicClientBuilder;
import org.jboss.wise.core.client.builder.WSDynamicClientBuilder;
-import
org.jboss.wise.core.client.impl.reflection.builder.ReflectionBasedWSDynamicClientBuilder;
import org.jboss.wise.core.client.jaxrs.RSDynamicClient;
-import org.jboss.wise.core.client.jaxrs.impl.RSDynamicClientImpl;
-import org.jboss.wise.core.consumer.WSConsumer;
+import org.jboss.wise.core.exception.WiseRuntimeException;
/**
* @author Stefano Maestri, stefano.maestri(a)javalinux.it
@@ -87,8 +88,13 @@
* to be called
*/
public static RSDynamicClient getJAXRSClient(String endpointURL,
RSDynamicClient.HttpMethod httpMethod, String produceMediaTypes, String consumeMediaTypes,
String userName, String password) {
- RSDynamicClient client = new RSDynamicClientImpl(endpointURL, produceMediaTypes,
consumeMediaTypes, httpMethod);
- return client;
+ RSDynamicClientBuilder builder = (RSDynamicClientBuilder) SpiLoader
+ .loadService("org.jboss.wise.core.client.builder.RSDynamicClientBuilder",
null);
+ if (builder == null)
+ {
+ throw new WiseRuntimeException("No RSDynamicClientBuilder implementation
found!");
+ }
+ return
builder.resourceURI(endpointURL).httpMethod(httpMethod).produceMediaTypes(produceMediaTypes).consumeMediaTypes(consumeMediaTypes).build();
}
/**
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WSDLResolver.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WSDLResolver.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/wsdlResolver/WSDLResolver.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -47,7 +47,6 @@
import org.jboss.logging.Logger;
import org.jboss.wise.core.utils.IDGenerator;
import org.jboss.ws.Constants;
-//import org.jboss.ws.tools.wsdl.JBossWSDLFactoryImpl;
import org.jboss.wsf.common.DOMUtils;
import org.jboss.wsf.common.DOMWriter;
import org.jboss.wsf.common.IOUtils;
Deleted:
core/trunk/core/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,267 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
- * individual contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of individual
- * contributors.
- *
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This software is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this software; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
- * site:
http://www.fsf.org.
- */
-
-package org.jboss.wise.core.client.jaxrs.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-import net.jcip.annotations.ThreadSafe;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.FileRequestEntity;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
-import org.apache.log4j.Logger;
-import org.jboss.wise.core.client.InvocationResult;
-import org.jboss.wise.core.client.impl.reflection.InvocationResultImpl;
-import org.jboss.wise.core.client.jaxrs.RSDynamicClient;
-import org.jboss.wise.core.mapper.WiseMapper;
-
-/*
- * TODO:
- * 1. return headers
- * 2. Support MultipartRequestEntity
- * 3. Support HttpClient properties
- * 4. Support setting headers
- * 5. Return the result in formats other than InputStream
- * 6. Exception handling
- * 7. Using jax-rs providers
- */
-@ThreadSafe
-public class RSDynamicClientImpl implements RSDynamicClient {
- private final Logger log = Logger.getLogger(RSDynamicClientImpl.class);
-
- private final String resourceURI;
- private String user;
- private String password;
- private final String produceMediaTypes;
- private final String consumeMediaTypes;
- private final HttpMethod httpMethod;
- private final HttpClient httpClient;
- private Map<String, String> requestHeaders = new HashMap<String,
String>();
-
- /**
- * Invoke JAXRS service.
- *
- * @param resourceURI
- * @param produceMediaTypes default to "* / *"
- * @param consumeMediaTypes default to "* / *"
- * @param httpMethod
- */
- public RSDynamicClientImpl( String resourceURI,
- String produceMediaTypes,
- String consumeMediaTypes,
- HttpMethod httpMethod ) {
- this.resourceURI = resourceURI;
- this.produceMediaTypes = produceMediaTypes;
- this.consumeMediaTypes = consumeMediaTypes;
- this.httpMethod = httpMethod;
-
- this.httpClient = new HttpClient();
- }
-
- public RSDynamicClientImpl( String resourceURI,
- String produceMediaTypes,
- String consumeMediaTypes,
- HttpMethod httpMethod,
- Map<String, String> requestHeaders ) {
- this.resourceURI = resourceURI;
- this.produceMediaTypes = produceMediaTypes;
- this.consumeMediaTypes = consumeMediaTypes;
- this.httpMethod = httpMethod;
- this.requestHeaders = requestHeaders;
-
- this.httpClient = new HttpClient();
- }
-
- public String getResourceURI() {
- return resourceURI;
- }
-
- public String getUser() {
- return user;
- }
-
- public String getPassword() {
- return password;
- }
-
- public HttpMethod getHttpMethod() {
- return httpMethod;
- }
-
- public String getProduceMediaTypes() {
- return produceMediaTypes;
- }
-
- public String getConsumeMediaTypes() {
- return consumeMediaTypes;
- }
-
- public InvocationResult invoke( Map<String, Object> inputObjects,
- WiseMapper mapper ) {
- // NOT SUPPORTED
- // transform inputObjects to String or InputStream using WiseMapper?
- return null;
- }
-
- public InvocationResult invoke( InputStream request,
- WiseMapper mapper ) {
- return invoke(new InputStreamRequestEntity(request), mapper);
- }
-
- public InvocationResult invoke( String request,
- WiseMapper mapper ) {
- RequestEntity requestEntity = null;
- try {
- requestEntity = new StringRequestEntity(request, produceMediaTypes,
"UTF-8");
- } catch (UnsupportedEncodingException e) {
- // TODO:
- }
- return invoke(requestEntity, mapper);
- }
-
- public InvocationResult invoke( byte[] request,
- WiseMapper mapper ) {
- return invoke(new ByteArrayRequestEntity(request), mapper);
- }
-
- public InvocationResult invoke( File request,
- WiseMapper mapper ) {
- return invoke(new FileRequestEntity(request, produceMediaTypes), mapper);
- }
-
- public InvocationResult invoke() {
- RequestEntity requestEntity = null;
- return invoke(requestEntity, null);
- }
-
- public InvocationResult invoke( RequestEntity requestEntity,
- WiseMapper mapper ) {
- InvocationResult result = null;
- Map<String, Object> responseHolder = new HashMap<String, Object>();
-
- if (HttpMethod.GET == httpMethod) {
- GetMethod get = new GetMethod(resourceURI);
- setRequestHeaders(get);
-
- try {
- int statusCode = httpClient.executeMethod(get);
- // TODO: Use InputStream
- String response = get.getResponseBodyAsString();
- responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
-
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
-
- // System.out.print(response);
- } catch (IOException e) {
- // TODO:
- } finally {
- get.releaseConnection();
- }
- } else if (HttpMethod.POST == httpMethod) {
- PostMethod post = new PostMethod(resourceURI);
- setRequestHeaders(post);
-
- post.setRequestEntity(requestEntity);
-
- try {
- int statusCode = httpClient.executeMethod(post);
- String response = post.getResponseBodyAsString();
- responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
-
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
-
- // System.out.print(response);
- } catch (IOException e) {
- // TODO:
- } finally {
- post.releaseConnection();
- }
- } else if (HttpMethod.PUT == httpMethod) {
- PutMethod put = new PutMethod(resourceURI);
- setRequestHeaders(put);
-
- put.setRequestEntity(requestEntity);
-
- try {
- int statusCode = httpClient.executeMethod(put);
- String response = put.getResponseBodyAsString();
- responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
-
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
-
- // System.out.print(response);
- } catch (IOException e) {
- // TODO:
- } finally {
- put.releaseConnection();
- }
- } else if (HttpMethod.DELETE == httpMethod) {
- DeleteMethod delete = new DeleteMethod(resourceURI);
- setRequestHeaders(delete);
-
- try {
- int statusCode = httpClient.executeMethod(delete);
- String response = delete.getResponseBodyAsString();
- responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
-
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
-
- // System.out.print(response);
- } catch (IOException e) {
- // TODO:
- } finally {
- delete.releaseConnection();
- }
- }
-
- return result;
- }
-
- private void setRequestHeaders( HttpMethodBase method ) {
- if (produceMediaTypes != null) {
- method.setRequestHeader("Content-Type", produceMediaTypes);
- }
-
- if (consumeMediaTypes != null) {
- method.setRequestHeader("Accept", consumeMediaTypes);
- }
-
- for (String headerName : requestHeaders.keySet()) {
- String headerValue = requestHeaders.get(headerName);
-
- method.setRequestHeader(headerName, headerValue);
- }
- }
-
-}
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/wsextensions/impl/WSSecurityEnabler.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/wsextensions/impl/WSSecurityEnabler.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/wsextensions/impl/WSSecurityEnabler.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -23,8 +23,8 @@
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
+
import org.jboss.wise.core.client.WSDynamicClient;
-import org.jboss.wise.core.client.WSEndpoint;
import org.jboss.wise.core.wsextensions.EnablerDelegate;
import org.jboss.wise.core.wsextensions.WSExtensionEnabler;
Deleted: core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java
===================================================================
--- core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java 2010-09-04
17:28:37 UTC (rev 393)
+++ core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,38 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-
-@XmlRootElement(name = "Book")
-public class Book {
- private String name;
- private long id;
-
- public Book() {
- init();
- }
-
- public Book(String name, long id) {
- this.name = name;
- this.id = id;
- }
-
- public void setName(String n) {
- name = n;
- }
-
- public String getName() {
- return name;
- }
-
- public void setId(long i) {
- id = i;
- }
- public long getId() {
- return id;
- }
- final void init() {
-
- }
-
-}
Deleted:
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,17 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-public class BookNotFoundDetails {
- private long id;
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
-}
Deleted:
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,17 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-import javax.xml.ws.WebFault;
-
-@WebFault
-public class BookNotFoundFault extends Exception {
- private BookNotFoundDetails details;
-
- public BookNotFoundFault(BookNotFoundDetails details) {
- super();
- this.details = details;
- }
-
- public BookNotFoundDetails getFaultInfo() {
- return details;
- }
-}
Deleted: core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,96 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Response;
-
-@Path("/bookstore")
-public class BookStore {
-
- private Map<Long, Book> books = new HashMap<Long, Book>();
- private long bookId = 123;
-
- private String currentBookId;
-
- public BookStore() {
- init();
- }
-
- @GET
- @Path("/books/{bookId}/")
- public Book getBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
- return doGetBook(id);
- }
-
- private Book doGetBook(String id) throws BookNotFoundFault {
- System.out.println("----invoking getBook with id: " + id);
- Book book = books.get(Long.parseLong(id));
- if (book != null) {
- return book;
- } else {
- BookNotFoundDetails details = new BookNotFoundDetails();
- details.setId(Long.parseLong(id));
- throw new BookNotFoundFault(details);
- }
- }
-
- @POST
- @Path("/books")
- @Produces("application/xml")
- @Consumes("application/xml")
- public Response addBook(Book book) {
- book.setId(++bookId);
- books.put(book.getId(), book);
-
- return Response.ok(book).build();
- }
-
- @PUT
- @Path("/books/")
- public Response updateBook(Book book) {
- Book b = books.get(book.getId());
-
- Response r;
- if (b != null) {
- books.put(book.getId(), book);
- r = Response.ok().build();
- } else {
- r = Response.notModified().build();
- }
-
- return r;
- }
-
- @DELETE
- @Path("/books/{bookId}/")
- public Response deleteBook(@PathParam("bookId") String id) {
- Book b = books.get(Long.parseLong(id));
-
- Response r;
- if (b != null) {
- r = Response.ok().build();
- } else {
- r = Response.notModified().build();
- }
-
- return r;
- }
-
- final void init() {
- Book book = new Book();
- book.setId(bookId);
- book.setName("CXF in Action");
- books.put(book.getId(), book);
- }
-}
-
-
Deleted:
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,106 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-import java.io.InputStream;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
-import org.jboss.wise.core.client.InvocationResult;
-import org.jboss.wise.core.client.factories.WSDynamicClientFactory;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ClientServerJaxrsTest extends AbstractClientServerTestBase {
-
- @BeforeClass
- public static void startServers() throws Exception {
- assertTrue("server did not launch correctly",
launchServer(JaxrsServer.class));
- }
-
- @Test
- public void testGetBook() throws Exception {
- RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
-
RSDynamicClient.HttpMethod.GET,
- null,
-
"application/xml");
- InvocationResult result = client.invoke();
- String response = (String)result.getResult().get(InvocationResult.RESPONSE);
-
- String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_get_book123.txt"));
-
- assertEquals(response, expected);
- }
-
- @Test
- public void testAddBook() throws Exception {
- RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
-
RSDynamicClient.HttpMethod.POST,
-
"application/xml",
-
"application/xml");
-
- InputStream request =
getClass().getResourceAsStream("/jaxrs/add_book.txt");
- InvocationResult result = client.invoke(request, null);
-
- String response = (String)result.getResult().get(InvocationResult.RESPONSE);
- System.out.println("-------------" + response);
-
- String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_add_book.txt"));
-
- assertEquals(response, expected);
- }
-
- @Test
- public void testUpdateBook() throws Exception {
- RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
-
RSDynamicClient.HttpMethod.PUT,
-
"application/xml",
-
"application/xml");
-
- InputStream request =
getClass().getResourceAsStream("/jaxrs/update_book.txt");
- InvocationResult result = client.invoke(request, null);
-
- String response = (String)result.getResult().get(InvocationResult.RESPONSE);
- int statusCode =
((Integer)result.getResult().get(InvocationResult.STATUS)).intValue();
- assertEquals(200, statusCode);
-
- // verify result
- client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
- RSDynamicClient.HttpMethod.GET,
- null,
- "application/xml");
- result = client.invoke();
- response = (String)result.getResult().get(InvocationResult.RESPONSE);
-
- String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_update_book.txt"));
-
- assertEquals(response, expected);
-
- // Roll back changes:
- client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
- RSDynamicClient.HttpMethod.PUT,
- "application/xml",
- "application/xml");
- request =
getClass().getResourceAsStream("/jaxrs/expected_get_book123.txt");
- result = client.invoke(request, null);
- }
-
- @Test
- public void testDeleteBook() throws Exception {
- RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
-
RSDynamicClient.HttpMethod.DELETE,
-
"application/xml",
-
"application/xml");
-
- InvocationResult result = client.invoke();
- int statusCode =
((Integer)result.getResult().get(InvocationResult.STATUS)).intValue();
- assertEquals(200, statusCode);
- }
-
- private String getStringFromInputStream( InputStream in ) throws Exception {
- CachedOutputStream bos = new CachedOutputStream();
- IOUtils.copy(in, bos);
- in.close();
- bos.close();
- return bos.getOut().toString();
- }
-
-}
Deleted: core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java 2010-09-04
17:28:37 UTC (rev 393)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -1,34 +0,0 @@
-package org.jboss.wise.core.client.jaxrs;
-
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-import org.apache.cxf.testutil.common.AbstractTestServerBase;
-
-public class JaxrsServer extends AbstractTestServerBase{
-
- protected void run() {
- JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
- sf.setResourceClasses(BookStore.class);
-
- // default life cycle is per-request, change it to singleton
- sf.setResourceProvider(BookStore.class,
- new SingletonResourceProvider(new BookStore()));
- sf.setAddress("http://localhost:9080/");
-
- sf.create();
- }
-
- public static void main(String[] args) {
- try {
- JaxrsServer s = new JaxrsServer();
-
- s.start();
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(-1);
- } finally {
- System.out.println("done!");
- }
- }
-
-}
Deleted: core/trunk/core/src/test/resources/jaxrs/add_book.txt
===================================================================
--- core/trunk/core/src/test/resources/jaxrs/add_book.txt 2010-09-04 17:28:37 UTC (rev
393)
+++ core/trunk/core/src/test/resources/jaxrs/add_book.txt 2010-09-05 21:43:40 UTC (rev
394)
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><name>CXF in Action -
2</name></Book>
\ No newline at end of file
Deleted: core/trunk/core/src/test/resources/jaxrs/expected_add_book.txt
===================================================================
--- core/trunk/core/src/test/resources/jaxrs/expected_add_book.txt 2010-09-04 17:28:37 UTC
(rev 393)
+++ core/trunk/core/src/test/resources/jaxrs/expected_add_book.txt 2010-09-05 21:43:40 UTC
(rev 394)
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>124</id><name>CXF in
Action - 2</name></Book>
\ No newline at end of file
Deleted: core/trunk/core/src/test/resources/jaxrs/expected_get_book123.txt
===================================================================
--- core/trunk/core/src/test/resources/jaxrs/expected_get_book123.txt 2010-09-04 17:28:37
UTC (rev 393)
+++ core/trunk/core/src/test/resources/jaxrs/expected_get_book123.txt 2010-09-05 21:43:40
UTC (rev 394)
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>123</id><name>CXF in
Action</name></Book>
\ No newline at end of file
Deleted: core/trunk/core/src/test/resources/jaxrs/expected_update_book.txt
===================================================================
--- core/trunk/core/src/test/resources/jaxrs/expected_update_book.txt 2010-09-04 17:28:37
UTC (rev 393)
+++ core/trunk/core/src/test/resources/jaxrs/expected_update_book.txt 2010-09-05 21:43:40
UTC (rev 394)
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>123</id><name>CXF in
Action - 3</name></Book>
\ No newline at end of file
Deleted: core/trunk/core/src/test/resources/jaxrs/update_book.txt
===================================================================
--- core/trunk/core/src/test/resources/jaxrs/update_book.txt 2010-09-04 17:28:37 UTC (rev
393)
+++ core/trunk/core/src/test/resources/jaxrs/update_book.txt 2010-09-05 21:43:40 UTC (rev
394)
@@ -1 +0,0 @@
-<Book><id>123</id><name>CXF in Action -
3</name></Book>
\ No newline at end of file
Property changes on: core/trunk/core-cxf
___________________________________________________________________
Name: svn:ignore
+ target
.project
.classpath
.settings
Added: core/trunk/core-cxf/pom.xml
===================================================================
--- core/trunk/core-cxf/pom.xml (rev 0)
+++ core/trunk/core-cxf/pom.xml 2010-09-05 21:43:40 UTC (rev 394)
@@ -0,0 +1,158 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.wise</groupId>
+ <artifactId>wise-core-cxf</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <name>Wise Core - CXF</name>
+ <
url>http://www.jboss.org/wise</url>
+
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.jboss.wise</groupId>
+ <artifactId>wise</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.wise</groupId>
+ <artifactId>wise-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ws.cxf</groupId>
+ <artifactId>jbossws-cxf-client</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-parser</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-extensions-json</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>sun.jdk</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.5.0</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>package</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <header>JBoss Wise API</header>
+ <footer>JBoss Wise API</footer>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>log4j.configuration</name>
+ <value>test-log4j.xml</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+
+</project>
Added:
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/CXFRSDynamicClientBuilder.java
===================================================================
---
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/CXFRSDynamicClientBuilder.java
(rev 0)
+++
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/CXFRSDynamicClientBuilder.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wise.core.client.jaxrs.impl;
+
+import java.net.ConnectException;
+
+import net.jcip.annotations.GuardedBy;
+import net.jcip.annotations.ThreadSafe;
+
+import org.jboss.wise.core.client.builder.RSDynamicClientBuilder;
+import org.jboss.wise.core.client.jaxrs.RSDynamicClient;
+import org.jboss.wise.core.client.jaxrs.RSDynamicClient.HttpMethod;
+import org.jboss.wise.core.exception.WiseRuntimeException;
+
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 05-Sep-2010
+ *
+ */
+@ThreadSafe
+public class CXFRSDynamicClientBuilder implements RSDynamicClientBuilder
+{
+
+ @GuardedBy("this")
+ private String resourceURI;
+ @GuardedBy("this")
+ private HttpMethod httpMethod;
+ @GuardedBy("this")
+ private String produceMediaTypes;
+ @GuardedBy("this")
+ private String consumeMediaTypes;
+
+
+ public synchronized RSDynamicClient build() throws IllegalStateException,
WiseRuntimeException
+ {
+ return new RSDynamicClientImpl(resourceURI, produceMediaTypes, consumeMediaTypes,
httpMethod);
+ }
+
+ public synchronized RSDynamicClientBuilder resourceURI(String resourceURI)
+ {
+ this.resourceURI = resourceURI;
+ return this;
+ }
+
+ public synchronized RSDynamicClientBuilder httpMethod(HttpMethod httpMethod)
+ {
+ this.httpMethod = httpMethod;
+ return this;
+ }
+
+ public synchronized RSDynamicClientBuilder produceMediaTypes(String
produceMediaTypes)
+ {
+ this.produceMediaTypes = produceMediaTypes;
+ return this;
+ }
+
+ public synchronized RSDynamicClientBuilder consumeMediaTypes(String
consumeMediaTypes)
+ {
+ this.consumeMediaTypes = consumeMediaTypes;
+ return this;
+ }
+
+ public synchronized String getResourceURI()
+ {
+ return this.resourceURI;
+ }
+
+ public synchronized String getProduceMediaTypes()
+ {
+ return this.produceMediaTypes;
+ }
+
+ public synchronized String getConsumeMediaTypes()
+ {
+ return this.consumeMediaTypes;
+ }
+
+ public synchronized HttpMethod getHttpMethod()
+ {
+ return this.httpMethod;
+ }
+
+}
Added:
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
===================================================================
---
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
(rev 0)
+++
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,267 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site:
http://www.fsf.org.
+ */
+
+package org.jboss.wise.core.client.jaxrs.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.jcip.annotations.ThreadSafe;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.jboss.wise.core.client.InvocationResult;
+import org.jboss.wise.core.client.impl.reflection.InvocationResultImpl;
+import org.jboss.wise.core.client.jaxrs.RSDynamicClient;
+import org.jboss.wise.core.mapper.WiseMapper;
+
+/*
+ * TODO:
+ * 1. return headers
+ * 2. Support MultipartRequestEntity
+ * 3. Support HttpClient properties
+ * 4. Support setting headers
+ * 5. Return the result in formats other than InputStream
+ * 6. Exception handling
+ * 7. Using jax-rs providers
+ */
+@ThreadSafe
+public class RSDynamicClientImpl implements RSDynamicClient {
+
+ private final String resourceURI;
+ private String user;
+ private String password;
+ private final String produceMediaTypes;
+ private final String consumeMediaTypes;
+ private final HttpMethod httpMethod;
+ private final HttpClient httpClient;
+ private Map<String, String> requestHeaders = new HashMap<String,
String>();
+
+ /**
+ * Invoke JAXRS service.
+ *
+ * @param resourceURI
+ * @param produceMediaTypes default to "* / *"
+ * @param consumeMediaTypes default to "* / *"
+ * @param httpMethod
+ */
+ public RSDynamicClientImpl( String resourceURI,
+ String produceMediaTypes,
+ String consumeMediaTypes,
+ HttpMethod httpMethod ) {
+ this.resourceURI = resourceURI;
+ this.produceMediaTypes = produceMediaTypes;
+ this.consumeMediaTypes = consumeMediaTypes;
+ this.httpMethod = httpMethod;
+
+ this.httpClient = new HttpClient();
+ }
+
+ public RSDynamicClientImpl( String resourceURI,
+ String produceMediaTypes,
+ String consumeMediaTypes,
+ HttpMethod httpMethod,
+ Map<String, String> requestHeaders ) {
+ this.resourceURI = resourceURI;
+ this.produceMediaTypes = produceMediaTypes;
+ this.consumeMediaTypes = consumeMediaTypes;
+ this.httpMethod = httpMethod;
+ this.requestHeaders = requestHeaders;
+
+ this.httpClient = new HttpClient();
+ }
+
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public HttpMethod getHttpMethod() {
+ return httpMethod;
+ }
+
+ public String getProduceMediaTypes() {
+ return produceMediaTypes;
+ }
+
+ public String getConsumeMediaTypes() {
+ return consumeMediaTypes;
+ }
+
+ public InvocationResult invoke( Map<String, Object> inputObjects,
+ WiseMapper mapper ) {
+ // NOT SUPPORTED
+ // transform inputObjects to String or InputStream using WiseMapper?
+ return null;
+ }
+
+ public InvocationResult invoke( InputStream request,
+ WiseMapper mapper ) {
+ return invoke(new InputStreamRequestEntity(request), mapper);
+ }
+
+ public InvocationResult invoke( String request,
+ WiseMapper mapper ) {
+ RequestEntity requestEntity = null;
+ try {
+ requestEntity = new StringRequestEntity(request, produceMediaTypes,
"UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // TODO:
+ }
+ return invoke(requestEntity, mapper);
+ }
+
+ public InvocationResult invoke( byte[] request,
+ WiseMapper mapper ) {
+ return invoke(new ByteArrayRequestEntity(request), mapper);
+ }
+
+ public InvocationResult invoke( File request,
+ WiseMapper mapper ) {
+ return invoke(new FileRequestEntity(request, produceMediaTypes), mapper);
+ }
+
+ public InvocationResult invoke() {
+ RequestEntity requestEntity = null;
+ return invoke(requestEntity, null);
+ }
+
+ public InvocationResult invoke( RequestEntity requestEntity,
+ WiseMapper mapper ) {
+ InvocationResult result = null;
+ Map<String, Object> responseHolder = new HashMap<String, Object>();
+
+ if (HttpMethod.GET == httpMethod) {
+ GetMethod get = new GetMethod(resourceURI);
+ setRequestHeaders(get);
+
+ try {
+ int statusCode = httpClient.executeMethod(get);
+ // TODO: Use InputStream
+ String response = get.getResponseBodyAsString();
+ responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
+
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+
+ // System.out.print(response);
+ } catch (IOException e) {
+ // TODO:
+ } finally {
+ get.releaseConnection();
+ }
+ } else if (HttpMethod.POST == httpMethod) {
+ PostMethod post = new PostMethod(resourceURI);
+ setRequestHeaders(post);
+
+ post.setRequestEntity(requestEntity);
+
+ try {
+ int statusCode = httpClient.executeMethod(post);
+ String response = post.getResponseBodyAsString();
+ responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
+
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+
+ // System.out.print(response);
+ } catch (IOException e) {
+ // TODO:
+ } finally {
+ post.releaseConnection();
+ }
+ } else if (HttpMethod.PUT == httpMethod) {
+ PutMethod put = new PutMethod(resourceURI);
+ setRequestHeaders(put);
+
+ put.setRequestEntity(requestEntity);
+
+ try {
+ int statusCode = httpClient.executeMethod(put);
+ String response = put.getResponseBodyAsString();
+ responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
+
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+
+ // System.out.print(response);
+ } catch (IOException e) {
+ // TODO:
+ } finally {
+ put.releaseConnection();
+ }
+ } else if (HttpMethod.DELETE == httpMethod) {
+ DeleteMethod delete = new DeleteMethod(resourceURI);
+ setRequestHeaders(delete);
+
+ try {
+ int statusCode = httpClient.executeMethod(delete);
+ String response = delete.getResponseBodyAsString();
+ responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
+
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+
+ // System.out.print(response);
+ } catch (IOException e) {
+ // TODO:
+ } finally {
+ delete.releaseConnection();
+ }
+ }
+
+ return result;
+ }
+
+ private void setRequestHeaders( HttpMethodBase method ) {
+ if (produceMediaTypes != null) {
+ method.setRequestHeader("Content-Type", produceMediaTypes);
+ }
+
+ if (consumeMediaTypes != null) {
+ method.setRequestHeader("Accept", consumeMediaTypes);
+ }
+
+ for (String headerName : requestHeaders.keySet()) {
+ String headerValue = requestHeaders.get(headerName);
+
+ method.setRequestHeader(headerName, headerValue);
+ }
+ }
+
+}
Added:
core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.core.client.builder.RSDynamicClientBuilder
===================================================================
---
core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.core.client.builder.RSDynamicClientBuilder
(rev 0)
+++
core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.core.client.builder.RSDynamicClientBuilder 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1 @@
+org.jboss.wise.core.client.jaxrs.impl.CXFRSDynamicClientBuilder
\ No newline at end of file
Added: core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java
===================================================================
--- core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/Book.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,38 @@
+package org.jboss.wise.core.client.jaxrs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+@XmlRootElement(name = "Book")
+public class Book {
+ private String name;
+ private long id;
+
+ public Book() {
+ init();
+ }
+
+ public Book(String name, long id) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public void setName(String n) {
+ name = n;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setId(long i) {
+ id = i;
+ }
+ public long getId() {
+ return id;
+ }
+ final void init() {
+
+ }
+
+}
Added:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java
===================================================================
---
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundDetails.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,17 @@
+package org.jboss.wise.core.client.jaxrs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class BookNotFoundDetails {
+ private long id;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+}
Added:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java
===================================================================
---
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookNotFoundFault.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,17 @@
+package org.jboss.wise.core.client.jaxrs;
+
+import javax.xml.ws.WebFault;
+
+@WebFault
+public class BookNotFoundFault extends Exception {
+ private BookNotFoundDetails details;
+
+ public BookNotFoundFault(BookNotFoundDetails details) {
+ super();
+ this.details = details;
+ }
+
+ public BookNotFoundDetails getFaultInfo() {
+ return details;
+ }
+}
Added: core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java
===================================================================
--- core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/BookStore.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,96 @@
+package org.jboss.wise.core.client.jaxrs;
+
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+@Path("/bookstore")
+public class BookStore {
+
+ private Map<Long, Book> books = new HashMap<Long, Book>();
+ private long bookId = 123;
+
+ private String currentBookId;
+
+ public BookStore() {
+ init();
+ }
+
+ @GET
+ @Path("/books/{bookId}/")
+ public Book getBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
+ return doGetBook(id);
+ }
+
+ private Book doGetBook(String id) throws BookNotFoundFault {
+ System.out.println("----invoking getBook with id: " + id);
+ Book book = books.get(Long.parseLong(id));
+ if (book != null) {
+ return book;
+ } else {
+ BookNotFoundDetails details = new BookNotFoundDetails();
+ details.setId(Long.parseLong(id));
+ throw new BookNotFoundFault(details);
+ }
+ }
+
+ @POST
+ @Path("/books")
+ @Produces("application/xml")
+ @Consumes("application/xml")
+ public Response addBook(Book book) {
+ book.setId(++bookId);
+ books.put(book.getId(), book);
+
+ return Response.ok(book).build();
+ }
+
+ @PUT
+ @Path("/books/")
+ public Response updateBook(Book book) {
+ Book b = books.get(book.getId());
+
+ Response r;
+ if (b != null) {
+ books.put(book.getId(), book);
+ r = Response.ok().build();
+ } else {
+ r = Response.notModified().build();
+ }
+
+ return r;
+ }
+
+ @DELETE
+ @Path("/books/{bookId}/")
+ public Response deleteBook(@PathParam("bookId") String id) {
+ Book b = books.get(Long.parseLong(id));
+
+ Response r;
+ if (b != null) {
+ r = Response.ok().build();
+ } else {
+ r = Response.notModified().build();
+ }
+
+ return r;
+ }
+
+ final void init() {
+ Book book = new Book();
+ book.setId(bookId);
+ book.setName("CXF in Action");
+ books.put(book.getId(), book);
+ }
+}
+
+
Added:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
===================================================================
---
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,106 @@
+package org.jboss.wise.core.client.jaxrs;
+
+import java.io.InputStream;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+import org.jboss.wise.core.client.InvocationResult;
+import org.jboss.wise.core.client.factories.WSDynamicClientFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ClientServerJaxrsTest extends AbstractClientServerTestBase {
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ assertTrue("server did not launch correctly",
launchServer(JaxrsServer.class));
+ }
+
+ @Test
+ public void testGetBook() throws Exception {
+ RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
+
RSDynamicClient.HttpMethod.GET,
+ null,
+
"application/xml");
+ InvocationResult result = client.invoke();
+ String response = (String)result.getResult().get(InvocationResult.RESPONSE);
+
+ String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_get_book123.txt"));
+
+ assertEquals(response, expected);
+ }
+
+ @Test
+ public void testAddBook() throws Exception {
+ RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
+
RSDynamicClient.HttpMethod.POST,
+
"application/xml",
+
"application/xml");
+
+ InputStream request =
getClass().getResourceAsStream("/jaxrs/add_book.txt");
+ InvocationResult result = client.invoke(request, null);
+
+ String response = (String)result.getResult().get(InvocationResult.RESPONSE);
+ System.out.println("-------------" + response);
+
+ String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_add_book.txt"));
+
+ assertEquals(response, expected);
+ }
+
+ @Test
+ public void testUpdateBook() throws Exception {
+ RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
+
RSDynamicClient.HttpMethod.PUT,
+
"application/xml",
+
"application/xml");
+
+ InputStream request =
getClass().getResourceAsStream("/jaxrs/update_book.txt");
+ InvocationResult result = client.invoke(request, null);
+
+ String response = (String)result.getResult().get(InvocationResult.RESPONSE);
+ int statusCode =
((Integer)result.getResult().get(InvocationResult.STATUS)).intValue();
+ assertEquals(200, statusCode);
+
+ // verify result
+ client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
+ RSDynamicClient.HttpMethod.GET,
+ null,
+ "application/xml");
+ result = client.invoke();
+ response = (String)result.getResult().get(InvocationResult.RESPONSE);
+
+ String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_update_book.txt"));
+
+ assertEquals(response, expected);
+
+ // Roll back changes:
+ client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books",
+ RSDynamicClient.HttpMethod.PUT,
+ "application/xml",
+ "application/xml");
+ request =
getClass().getResourceAsStream("/jaxrs/expected_get_book123.txt");
+ result = client.invoke(request, null);
+ }
+
+ @Test
+ public void testDeleteBook() throws Exception {
+ RSDynamicClient client =
WSDynamicClientFactory.getJAXRSClient("http://localhost:9080/bookstore/books/123",
+
RSDynamicClient.HttpMethod.DELETE,
+
"application/xml",
+
"application/xml");
+
+ InvocationResult result = client.invoke();
+ int statusCode =
((Integer)result.getResult().get(InvocationResult.STATUS)).intValue();
+ assertEquals(200, statusCode);
+ }
+
+ private String getStringFromInputStream( InputStream in ) throws Exception {
+ CachedOutputStream bos = new CachedOutputStream();
+ IOUtils.copy(in, bos);
+ in.close();
+ bos.close();
+ return bos.getOut().toString();
+ }
+
+}
Added:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java
===================================================================
--- core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java
(rev 0)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/JaxrsServer.java 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1,34 @@
+package org.jboss.wise.core.client.jaxrs;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.testutil.common.AbstractTestServerBase;
+
+public class JaxrsServer extends AbstractTestServerBase{
+
+ protected void run() {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(BookStore.class);
+
+ // default life cycle is per-request, change it to singleton
+ sf.setResourceProvider(BookStore.class,
+ new SingletonResourceProvider(new BookStore()));
+ sf.setAddress("http://localhost:9080/");
+
+ sf.create();
+ }
+
+ public static void main(String[] args) {
+ try {
+ JaxrsServer s = new JaxrsServer();
+
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+
+}
Added: core/trunk/core-cxf/src/test/resources/jaxrs/add_book.txt
===================================================================
--- core/trunk/core-cxf/src/test/resources/jaxrs/add_book.txt (rev
0)
+++ core/trunk/core-cxf/src/test/resources/jaxrs/add_book.txt 2010-09-05 21:43:40 UTC (rev
394)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><name>CXF in Action -
2</name></Book>
\ No newline at end of file
Added: core/trunk/core-cxf/src/test/resources/jaxrs/expected_add_book.txt
===================================================================
--- core/trunk/core-cxf/src/test/resources/jaxrs/expected_add_book.txt
(rev 0)
+++ core/trunk/core-cxf/src/test/resources/jaxrs/expected_add_book.txt 2010-09-05 21:43:40
UTC (rev 394)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>124</id><name>CXF in
Action - 2</name></Book>
\ No newline at end of file
Added: core/trunk/core-cxf/src/test/resources/jaxrs/expected_get_book123.txt
===================================================================
--- core/trunk/core-cxf/src/test/resources/jaxrs/expected_get_book123.txt
(rev 0)
+++ core/trunk/core-cxf/src/test/resources/jaxrs/expected_get_book123.txt 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>123</id><name>CXF in
Action</name></Book>
\ No newline at end of file
Added: core/trunk/core-cxf/src/test/resources/jaxrs/expected_update_book.txt
===================================================================
--- core/trunk/core-cxf/src/test/resources/jaxrs/expected_update_book.txt
(rev 0)
+++ core/trunk/core-cxf/src/test/resources/jaxrs/expected_update_book.txt 2010-09-05
21:43:40 UTC (rev 394)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>123</id><name>CXF in
Action - 3</name></Book>
\ No newline at end of file
Added: core/trunk/core-cxf/src/test/resources/jaxrs/update_book.txt
===================================================================
--- core/trunk/core-cxf/src/test/resources/jaxrs/update_book.txt
(rev 0)
+++ core/trunk/core-cxf/src/test/resources/jaxrs/update_book.txt 2010-09-05 21:43:40 UTC
(rev 394)
@@ -0,0 +1 @@
+<Book><id>123</id><name>CXF in Action -
3</name></Book>
\ No newline at end of file
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2010-09-04 17:28:37 UTC (rev 393)
+++ core/trunk/pom.xml 2010-09-05 21:43:40 UTC (rev 394)
@@ -201,6 +201,12 @@
</dependency>
<dependency>
+ <groupId>org.jboss.ws.cxf</groupId>
+ <artifactId>jbossws-cxf-client</artifactId>
+ <version>3.3.1.GA</version>
+ </dependency>
+
+ <dependency>
<groupId>org.milyn</groupId>
<artifactId>milyn-smooks-core</artifactId>
<version>1.2.1</version>
@@ -544,9 +550,9 @@
<name>cxf.stack</name>
</property>
</activation>
- <!-- <modules>
+ <modules>
<module>core-cxf</module>
- </modules> -->
+ </modules>
</profile>
</profiles>