JAX – WS – 05 – Trace SOAP Messages

Merhaba Arkadaslar
Bu bolumde SOAP Mesajlarinin trace edilmesi/izlenilmesini inceleyecegiz.

Bunun icin 2 yaklasim kullanacagiz.

  • TCP/IP Monitor
  • System Property

Service Endpoint Interface & Service Implementation Bean

Oncelikle ilk ornegimizde oldugu gibi basit bir Web Service uygulamasi yapalim.

TraceWriter.java

package service;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface TraceWriter {

	@WebMethod
	public String getMessage();
}

TraceWriterImpl.java

package service;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(endpointInterface = "service.TraceWriter")
public class TraceWriterImpl implements TraceWriter{

	@WebMethod
	@Override
	public String getMessage() {
		return "Trace Message!";
	}

}

Publisher

WebServicePublisher.java

package publisher;

import javax.xml.ws.Endpoint;

import service.TraceWriterImpl;

public class WebServicePublisher {

	private static String WEB_SERVICE_URL = "http://localhost:8888/injavawetrust/trace.writer?wsdl";

	public static void main(String[] args) {
		Endpoint.publish(WEB_SERVICE_URL, new TraceWriterImpl());
		System.out.println("Web Service is started.");
	}

}

Eclipse TCP/IP Monitor Menu

Eclipse’te Preferences -> Run/Debug -> TCP/IP Monitor menusune gelelim.

Sonrasinda Add.. butonuna tiklayalim.
Karsimiza New Monitor menusu acilacaktir.

Host name olarak localhost ya da 127.0.0.1 verebiliriz.
Port olarak Web Service’imizi Publish edecegimiz portun bilgisini veriyoruz ; 8888
Type olarak TCP/IP seciyoruz.

Local Monitoring portu icin 8082 gibi kullanimda olmayan bir port bilgisi verebiliriz.

OK deyip ekledikten sonra Start butonuna basalim…
Status sekmesinde “Started” olarak gorduysek her sey yolunda demektir.

Trace Client

TraceMonitorClient.java
Onceki orneklerimizde yaptigimiz gibi Client sinifimizi yazalim.
Burada fark olarak , Web Service’i Publish ettigimiz 8888 portunu degil TCP/IP Monitor menude tanimladigimiz 8082 portunu kullaniyoruz.

package client;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import service.TraceWriter;

public class TraceMonitorClient {

	// private static String WEB_SERVICE_WSDL_URL =
	// "http://localhost:8888/injavawetrust/trace.writer?wsdl";

	// TCP/IP Monitor "local port"
	private static String WEB_SERVICE_WSDL_URL = "http://localhost:8082/injavawetrust/trace.writer?wsdl";

	public static void main(String[] args) throws MalformedURLException {

		URL url = new URL(WEB_SERVICE_WSDL_URL);
		QName qname = new QName("http://service/", "TraceWriterImplService");
		Service service = Service.create(url, qname);

		TraceWriter traceWriter = service.getPort(TraceWriter.class);

		String message = traceWriter.getMessage();
		System.out.println(message);
	}
}

Eclipse TCP/IP Monitor View

Eclipse’te Window -> Show View -> Other …
TCP/IP Monitor menuyu ekleyelim.

Run Application & Test Client

Web Service’imizi Publish edelim. (WebServicePublisher.java)

Eclipse Console’da

Web Service is started.
Trace Message!

TCP/IP Monitor’de

GET /injavawetrust/trace.writer?wsdl HTTP/1.1
User-Agent: Java/1.8.0_121
Host: localhost:8082
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

POST /injavawetrust/trace.writer HTTP/1.1
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://service/TraceWriter/getMessageRequest"
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
Host: localhost:8082
Connection: keep-alive
Content-Length: 177

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getMessage xmlns:ns2="http://service/"></ns2:getMessage></S:Body></S:Envelope>


HTTP/1.1 200 OK
Date: Sat, 18 Mar 2017 18:00:54 GMT
Transfer-encoding: chunked
Content-type: text/xml;charset=utf-8

7a9
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service/" name="TraceWriterImplService">
<types></types>
<message name="getMessage"></message>
<message name="getMessageResponse">
<part name="return" type="xsd:string"></part>
</message>
<portType name="TraceWriter">
<operation name="getMessage">
<input wsam:Action="http://service/TraceWriter/getMessageRequest" message="tns:getMessage"></input>
<output wsam:Action="http://service/TraceWriter/getMessageResponse" message="tns:getMessageResponse"></output>
</operation>
</portType>
<binding name="TraceWriterImplPortBinding" type="tns:TraceWriter">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
<operation name="getMessage">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" namespace="http://service/"></soap:body>
</input>
<output>
<soap:body use="literal" namespace="http://service/"></soap:body>
</output>
</operation>
</binding>
<service name="TraceWriterImplService">
<port name="TraceWriterImplPort" binding="tns:TraceWriterImplPortBinding">
<soap:address location="http://localhost:8082/injavawetrust/trace.writer"></soap:address>
</port>
</service>
</definitions>
0

HTTP/1.1 200 OK
Date: Sat, 18 Mar 2017 18:00:54 GMT
Transfer-encoding: chunked
Content-type: text/xml; charset=utf-8

ec
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getMessageResponse xmlns:ns2="http://service/"><return>TraceWriterImpl#getMessage</return></ns2:getMessageResponse></S:Body></S:Envelope>
0

Bir baska yaklasim olarak System property kullanabiliriz. Bunun icin oncelikle TCP/IP monitorun calismasini durduralim.

When you invoke the Web Service, just pass the system property 
com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true, 
it prints out the request and response message.

https://metro.java.net/nonav/1.2/guide/Logging.html
https://gist.github.com/Barlog-M/d50f015fcc259a407b4f

TracePropertyClient.java

package client;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import service.TraceWriter;

public class TracePropertyClient {

	// TCP/IP Monitor "local port"
	private static String WEB_SERVICE_WSDL_URL = "http://localhost:8888/injavawetrust/trace.writer?wsdl";

	public static void main(String[] args) throws MalformedURLException {

		// When you invoke the Web Service, just pass the system property
		// com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true, it
		// prints out the request and response message.

		System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");

		URL url = new URL(WEB_SERVICE_WSDL_URL);
		QName qname = new QName("http://service/", "TraceWriterImplService");
		Service service = Service.create(url, qname);

		TraceWriter traceWriter = service.getPort(TraceWriter.class);

		String message = traceWriter.getMessage();
		System.out.println(message);
	}
}

Ornegimizi calistirdigimizda;

---[HTTP request - http://localhost:8888/injavawetrust/trace.writer]---
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://service/TraceWriter/getMessageRequest"
User-Agent:
JAX-WS RI 2.2.9-b130926.1035
svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
	<S:Body>
		<ns2:getMessage xmlns:ns2="http://service/"></ns2:getMessage>
	</S:Body>
</S:Envelope>
--------------------

---[HTTP response -
http://localhost:8888/injavawetrust/trace.writer - 200]---
null: HTTP/1.1
200 OK
Content-type: text/xml; charset=utf-8
Date: Sat, 07 Oct 2017
09:54:07 GMT
Transfer-encoding: chunked
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
	<S:Body>
		<ns2:getMessageResponse xmlns:ns2="http://service/">
			<return>Trace Message!</return>
		</ns2:getMessageResponse>
	</S:Body>
</S:Envelope>
--------------------

Trace Message!

Github kaynak kodlar / source folder
injavawetrust-jaxws-tutorial

injavawetrust.jaxws.trace

Yazimi burada sonlandiriyorum.
Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *