Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758
{"id":765,"date":"2014-05-22T21:45:40","date_gmt":"2014-05-23T00:45:40","guid":{"rendered":"http:\/\/www.feltex.com.br\/felix\/?p=765"},"modified":"2014-12-26T16:45:08","modified_gmt":"2014-12-26T18:45:08","slug":"construindo-web-service-com-jax-ws","status":"publish","type":"post","link":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/","title":{"rendered":"Construindo Web Service com JAX-WS"},"content":{"rendered":"

Construindo Web Service com JAX-WS<\/H1><\/p>\n

\"WebService-JAX-WS02\"
\nOl\u00e1 amigos,
\n Hoje criaremos um web Service com a API JAX-WS. JAX-WS \u00e9 uma tecnologia para a constru\u00e7\u00e3o de servi\u00e7os web e clientes que se comunicam via XML. JAX-WS permite aos desenvolvedores escrever servi\u00e7os orientados a mensagem, bem como servi\u00e7os de Chamada Remota de Procedimentos (RPC) orientadas para a web.<\/p>\n

O JAX-WS \u00e9 baseado no protocolo SOAP – uma opera\u00e7\u00e3o de chamada a um servi\u00e7o web que \u00e9 representado por um protocolo baseado em XML. A especifica\u00e7\u00e3o SOAP define a estrutura de envelope, regras de codifica\u00e7\u00e3o, e as conven\u00e7\u00f5es para a representa\u00e7\u00e3o de chamadas de servi\u00e7o web e respostas. Essas chamadas e respostas s\u00e3o transmitidas como mensagens SOAP (arquivos XML) sobre HTTP.<\/p>\n

Para quem j\u00e1 trabalhou com web Service, sabe que esta \u00e9 uma forma de integrar sistemas atrav\u00e9s de chamadas de rede e independente de linguagem de programa\u00e7\u00e3o.
\n Ent\u00e3o vamos l\u00e1! M\u00e3os \u00e0 obra.<\/p>\n


\n

1. Criando a interface<\/H2>
\n Para come\u00e7armos vamos construir nossa Interface de m\u00e9todos. Ela \u00e9 respons\u00e1vel por disponibilizar as assinaturas de m\u00e9todos que ser\u00e3o implementados por nossa classe de servi\u00e7o. Em seguida esses m\u00e9todos ser\u00e3o publicados em um servidor.<\/p>\n

Digite o c\u00f3digo abaixo em um arquivo chamado “GeraNumero.java”:<\/p>\n

\r\npackage br.com.feltex.webservice.service;\r\n\r\nimport javax.jws.WebMethod;\r\nimport javax.jws.WebService;\r\nimport javax.jws.soap.SOAPBinding;\r\nimport javax.jws.soap.SOAPBinding.Style;\r\nimport javax.jws.soap.SOAPBinding.Use;\r\n\r\n@WebService\r\n@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)\r\npublic interface GeraNumero {\r\n\t@WebMethod\r\n\tpublic double gerarNumero();\r\n}\r\n<\/pre>\n

2. Classe que implementa o servi\u00e7o<\/H2>
\n Em seguida temos que criar a classe que possui o m\u00e9todo de gera\u00e7\u00e3o de n\u00fameros aleat\u00f3rios. Observe que ele implementa a Interface “GeraNumero”. Por isso a classe deve implementar os m\u00e9todos definidos por ela.<\/p>\n
\r\npackage br.com.feltex.webservice.service;\r\n\r\nimport javax.jws.WebService;\r\n\r\n@WebService(endpointInterface = \"br.com.feltex.webservice.service.GeraNumero\")\r\npublic class GeradoNumeroImpl implements GeraNumero {\r\n\t@Override\r\n\tpublic double gerarNumero() {\r\n\t\treturn Math.random() * 11000;\r\n\t}\r\n}\r\n<\/pre>\n

3. Publica\u00e7\u00e3o do Servi\u00e7o<\/H2>
\n Por \u00faltimo teremos a classe que ir\u00e1 inicializar o nosso servi\u00e7o e deixar\u00e1 dispon\u00edvel a chamada via HTTP.<\/p>\n
\r\npackage br.com.feltex.webservice.tool;\r\n\r\nimport javax.xml.ws.Endpoint;\r\n\r\nimport br.com.feltex.webservice.service.GeradoNumeroImpl;\r\n\r\npublic class Publicador {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\"In\u00edcio Publicador\");\t\t \r\n\t\tEndpoint.publish(\"http:\/\/localhost:8080\/gerador\",new GeradoNumeroImpl());\r\n\t\tSystem.out.println(\"Fim Publicador\");\r\n\t}\r\n}\r\n<\/pre>\n

4. Verifica\u00e7\u00e3o da disponibilidade do servi\u00e7o.<\/H2>
\n Execute a classe Publicador e voc\u00ea ver\u00e1 que o servi\u00e7o estar\u00e1 no ar!
\n Para voc\u00ea ver se o servi\u00e7o est\u00e1 no ar, ser\u00e1 necess\u00e1rio abrir o browser e fazer a seguinte chamada:http:\/\/localhost:8080\/gerador?wsdl<\/strong><\/p>\n

O resultado deve ser algo parecido como:<\/p>\n

\r\n\r\n\r\n\r\n<\/xsd:import>\r\n<\/xsd:schema>\r\n<\/types>\r\n\r\n<\/part>\r\n<\/message>\r\n\r\n<\/part>\r\n<\/message>\r\n\r\n\r\n<\/input>\r\n<\/output>\r\n<\/operation>\r\n<\/portType>\r\n\r\n<\/soap:binding>\r\n\r\n<\/soap:operation>\r\n\r\n<\/soap:body>\r\n<\/input>\r\n\r\n<\/soap:body>\r\n<\/output>\r\n<\/operation>\r\n<\/binding>\r\n\r\n\r\n<\/soap:address>\r\n<\/port>\r\n<\/service>\r\n<\/definitions>\r\n<\/pre>\n

5. Conclus\u00e3o<\/H2><\/p>\n

Esses s\u00e3o os passos essenciais para disponibilizarmos um Web Service em Java para que seja utilizado por outras aplica\u00e7\u00f5es. Quem desejar fazer uso desse servi\u00e7o deve criar um Cliente atrav\u00e9s do WSDL <\/strong> disponibilizado hoje. \u00c9 poss\u00edvel tamb\u00e9m utilizar um cliente como o SoapUI<\/a> uma ferramenta que facilita o teste de webservices.<\/p>\n

Por hoje \u00e9 s\u00f3! E vida que segue.<\/p>\n

Links relacionados


\n
WebService com EJB Hello Wolrd<\/a><\/p>\n

Web Service RESTEasy no servidor WildFly \u2013 Hello world<\/a><\/p>\n

Tutorial JAX-WS<\/a><\/p>\n

N\u00e3o se esque\u00e7a de curtir este post nas rede sociais. D\u00ea a sua contribui\u00e7\u00e3o social e ajude o autor:<\/H2><\/p>\n","protected":false},"excerpt":{"rendered":"

Construindo Web Service com JAX-WS Ol\u00e1 amigos, Hoje criaremos um web Service com a API JAX-WS. JAX-WS \u00e9 uma tecnologia para a constru\u00e7\u00e3o de servi\u00e7os web e clientes que se comunicam via XML. JAX-WS permite aos desenvolvedores escrever servi\u00e7os orientados …<\/p>\n

Construindo Web Service com JAX-WS<\/span> Read More »<\/a><\/p>\n

<\/p>\n","protected":false},"author":2,"featured_media":1691,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[1,37],"tags":[38],"yoast_head":"\nWeb Service Construindo Servi\u00e7os com JAX-WS<\/title>\n<meta name=\"description\" content=\"Construindo um web Service com o framework Apache CFX\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Web Service Construindo Servi\u00e7os com JAX-WS\" \/>\n<meta property=\"og:description\" content=\"Construindo um web Service com o framework Apache CFX\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/\" \/>\n<meta property=\"og:site_name\" content=\"Aprenda Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/feltex.br\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-23T00:45:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-12-26T18:45:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"felix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/\",\"name\":\"Aprenda Java\",\"description\":\"Cursos de java, SQL e Engenharia de Software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#primaryimage\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png\",\"contentUrl\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png\",\"width\":512,\"height\":512},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#webpage\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/\",\"name\":\"Web Service Construindo Servi\\u00e7os com JAX-WS\",\"isPartOf\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#primaryimage\"},\"datePublished\":\"2014-05-23T00:45:40+00:00\",\"dateModified\":\"2014-12-26T18:45:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1a65b5af03f702af1459503a261d2af5\"},\"description\":\"Construindo um web Service com o framework Apache CFX\",\"breadcrumb\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Construindo Web Service com JAX-WS\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1a65b5af03f702af1459503a261d2af5\",\"name\":\"felix\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#personlogo\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/17ef6c9af55f4522a01f39b1382b565d?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/17ef6c9af55f4522a01f39b1382b565d?s=96&r=g\",\"caption\":\"felix\"},\"url\":\"https:\/\/www.feltex.com.br\/felix\/author\/felix\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Web Service Construindo Servi\u00e7os com JAX-WS","description":"Construindo um web Service com o framework Apache CFX","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/","og_locale":"pt_BR","og_type":"article","og_title":"Web Service Construindo Servi\u00e7os com JAX-WS","og_description":"Construindo um web Service com o framework Apache CFX","og_url":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/","og_site_name":"Aprenda Java","article_publisher":"https:\/\/www.facebook.com\/feltex.br","article_published_time":"2014-05-23T00:45:40+00:00","article_modified_time":"2014-12-26T18:45:08+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png","type":"image\/png"}],"twitter_misc":{"Escrito por":"felix","Est. tempo de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.feltex.com.br\/felix\/#website","url":"https:\/\/www.feltex.com.br\/felix\/","name":"Aprenda Java","description":"Cursos de java, SQL e Engenharia de Software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#primaryimage","inLanguage":"pt-BR","url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png","contentUrl":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/05\/WebService-JAX-WS.png","width":512,"height":512},{"@type":"WebPage","@id":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#webpage","url":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/","name":"Web Service Construindo Servi\u00e7os com JAX-WS","isPartOf":{"@id":"https:\/\/www.feltex.com.br\/felix\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#primaryimage"},"datePublished":"2014-05-23T00:45:40+00:00","dateModified":"2014-12-26T18:45:08+00:00","author":{"@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1a65b5af03f702af1459503a261d2af5"},"description":"Construindo um web Service com o framework Apache CFX","breadcrumb":{"@id":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.feltex.com.br\/felix\/construindo-web-service-com-jax-ws\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Construindo Web Service com JAX-WS"}]},{"@type":"Person","@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1a65b5af03f702af1459503a261d2af5","name":"felix","image":{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/#personlogo","inLanguage":"pt-BR","url":"https:\/\/secure.gravatar.com\/avatar\/17ef6c9af55f4522a01f39b1382b565d?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/17ef6c9af55f4522a01f39b1382b565d?s=96&r=g","caption":"felix"},"url":"https:\/\/www.feltex.com.br\/felix\/author\/felix\/"}]}},"_links":{"self":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/765"}],"collection":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/comments?post=765"}],"version-history":[{"count":20,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"predecessor-version":[{"id":1068,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/765\/revisions\/1068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media\/1691"}],"wp:attachment":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}