-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Juan Saad <[email protected]>
- Loading branch information
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Class-Path: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/classes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-ext | ||
xmlns="http://websphere.ibm.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_1.xsd" | ||
version="1.1"> | ||
|
||
<reload-interval value="3"/> | ||
<context-root uri="dportenis-rest-broker" /> | ||
<enable-directory-browsing value="false"/> | ||
<enable-file-serving value="true"/> | ||
<enable-reloading value="true"/> | ||
<enable-serving-servlets-by-class-name value="false" /> | ||
|
||
</web-ext> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> | ||
<display-name>dportenis-rest-broker</display-name> | ||
<servlet> | ||
<description> | ||
JAX-RS Tools Generated - Do not modify</description> | ||
<servlet-name>JAX-RS Servlet</servlet-name> | ||
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class> | ||
<init-param> | ||
<param-name>javax.ws.rs.Application</param-name> | ||
<param-value>com.dportenis.rest.broker.BrokerApplication</param-value> | ||
</init-param> | ||
<load-on-startup>1</load-on-startup> | ||
<enabled>true</enabled> | ||
<async-supported>false</async-supported> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>JAX-RS Servlet</servlet-name> | ||
<url-pattern> | ||
/jaxrs/*</url-pattern> | ||
</servlet-mapping> | ||
</web-app> |
18 changes: 18 additions & 0 deletions
18
dportenis-rest-broker/src/com/dportenis/rest/broker/BrokerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.dportenis.rest.broker; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.ws.rs.core.Application; | ||
|
||
import com.dportenis.rest.module.OrdenCompra; | ||
|
||
public class BrokerApplication extends Application { | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
Set<Class<?>> classes = new HashSet<Class<?>>(); | ||
classes.add(OrdenCompra.class); | ||
return classes; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dportenis-rest-broker/src/com/dportenis/rest/module/OrdenCompra.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dportenis.rest.module; | ||
|
||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import com.ibm.json.java.JSONObject; | ||
|
||
@Path(value="/po") | ||
public class OrdenCompra { | ||
|
||
public OrdenCompra() { | ||
} | ||
|
||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path(value="/datos") | ||
public JSONObject doExec(JSONObject requestObj) | ||
{ | ||
JSONObject responseObj = new JSONObject(); | ||
int code = 0; | ||
String message = null; | ||
|
||
try | ||
{ | ||
message = "mensaje recibido: " + requestObj.toString(); | ||
} | ||
catch (Exception e) | ||
{ | ||
code = 1; | ||
message = e.getMessage(); | ||
e.printStackTrace(); | ||
} | ||
finally | ||
{ | ||
responseObj.put("codigo", code); | ||
responseObj.put("mensaje", message); | ||
} | ||
|
||
return responseObj; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
dportenis-rest-broker/test/com/deportenis/rest/test/TestREST.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.deportenis.rest.test; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.ibm.json.java.JSONObject; | ||
|
||
public class TestREST { | ||
|
||
private String url = "http://localhost:9080/dportenis-rest-broker/jaxrs/po/datos"; | ||
private int timeout = 10000; // default to 10 secs | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testSendData() { | ||
JSONObject request = new JSONObject(); | ||
request.put("batchId", "XXXXXX"); | ||
try { | ||
setTimeout(5000); | ||
JSONObject response = doPost(request); | ||
System.out.println(response.toString()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void setTimeout(int timeout) { | ||
this.timeout = timeout; | ||
} | ||
|
||
private JSONObject doPost(JSONObject data) throws Exception { | ||
// Create HTTP Client | ||
RequestConfig config = RequestConfig.custom() | ||
.setConnectTimeout(timeout) | ||
.setSocketTimeout(timeout).build(); | ||
HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); | ||
|
||
// Create HTTP Request | ||
HttpPost request = new HttpPost(url); | ||
|
||
// Add additional headers | ||
request.addHeader("Content-Type", "application/json"); | ||
|
||
// Set Body | ||
StringEntity entity = new StringEntity(data.serialize()); | ||
request.setEntity(entity); | ||
|
||
// Execute your request and catch response | ||
HttpResponse response = httpClient.execute(request); | ||
|
||
// Get string response | ||
HttpEntity resEntity = response.getEntity(); | ||
return JSONObject.parse(IOUtils.toString(resEntity.getContent())); | ||
} | ||
|
||
} |