SOAP Currency Converter WSDL (by http://webservicex.net):
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
SOAP Client:
public class CurrencyTest {
public static void main(String[] args) {
try {
CurrencyConvertorLocator locator = new CurrencyConvertorLocator();
URL url = new URL("http://www.webservicex.net/CurrencyConvertor.asmx");
CurrencyConvertorSoapStub stub = new CurrencyConvertorSoapStub(url, locator);
double rate = stub.conversionRate(Currency.USD, Currency.BRL);
System.out.println(" 1 Dólar em Reais? " + ( 1 * rate ));
} catch (Exception e) {
e.printStackTrace();
}
}
}REST Configuração Jersey:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<description>example-rest</description>
<display-name>example-rest</display-name>
<servlet>
<servlet-name>example-services</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example.service_package</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>example-services</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>REST Server:
public class ExampleServer {
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject exampleGet(@QueryParam("param1") String param1) {
JSONObject json = new JSONObject();
JSONArray array = new JSONArray();
JSONObject jsonProduct = new JSONObject();
jsonProduct.put("tipo","celular");
jsonProduct.put("nome","nokia");
jsonProduct.put("valor","US$ 1900,00");
array.add(jsonProduct);
json.put("produtos", array);
return json;
}
}REST Client:
Meus produtos disponíveis:<br/>
<!-- COMBO -->
<select id="combo">
<option>Selecione o produto</option>
</select>
<!-- JQUERY -->
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<!-- CHAMADA AJAX -->
<script type="text/javascript" language="javascript">
var array= new Array();
$.ajax({
type: "GET",
cache: false,
url: "http://localhost:8080/example-rest/service/example/get?param1=teste",
success: function(data){
array = data.produtos;
for(var i = 0; i< array.length; i++) {
$("#combo").append("<option value=\""+array[i].tipo+"\">["
+array[i].tipo+"] "
+array[i].nome+"- "
+array[i].valor+
"</option>");
} } }); </script>
Nenhum comentário:
Postar um comentário