锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品国产免费,亚洲A∨精品一区二区三区下载 ,永久亚洲成a人片777777http://www.tkk7.com/liuzheng/category/28171.htmlzh-cnFri, 11 Jan 2008 04:05:25 GMTFri, 11 Jan 2008 04:05:25 GMT60Web Service涓湁鍏砏SDL鐨勫涔犲績寰?/title><link>http://www.tkk7.com/liuzheng/articles/174523.html</link><dc:creator>鍒橀摦 </dc:creator><author>鍒橀摦 </author><pubDate>Fri, 11 Jan 2008 02:20:00 GMT</pubDate><guid>http://www.tkk7.com/liuzheng/articles/174523.html</guid><wfw:comment>http://www.tkk7.com/liuzheng/comments/174523.html</wfw:comment><comments>http://www.tkk7.com/liuzheng/articles/174523.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/liuzheng/comments/commentRss/174523.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/liuzheng/services/trackbacks/174523.html</trackback:ping><description><![CDATA[WSDL寰堥噸瑕佺殑鍑犱釜Elements錛?br /> <table class="ex" width="100%" border="1"> <tbody> <tr> <td valign="top"><portType></td> <td valign="top">The operations performed by the web service</td> </tr> <tr> <td valign="top"><message></td> <td valign="top">The messages used by the web service</td> </tr> <tr> <td valign="top"><types></td> <td valign="top">The data types used by the web service</td> </tr> <tr> <td valign="top"><binding></td> <td valign="top">The communication protocols used by the web service</td> </tr> </tbody> </table> 1.浠?lt;service>浣滀負鍏ュ彛錛?lt;service>鐨勫瓙鍏冪礌<address>瀹氫箟浜唚ebservice 鐨刄RL   錛屽瓙鍏冪礌<port>涓庝竴涓猙inding鐩稿叧鑱?br /> 2.鍦?lt;binding>涓畾涔変簡璺熶粈涔?lt;portType>榪涜緇戝畾錛屽強鍏舵庢牱緇戝畾錛屼嬌鐢ㄧ殑鏄痳pc榪樻槸document錛岃繕瀹氫箟浜嗙粦瀹氫簡鍝簺鏂規硶<operation>,鍙婂叾鏂規硶閲岄潰鐨?lt;input>鍜?lt;output>鐨刴essage鍐呭銆傝繖閲屽氨鍜?lt;message>鐩稿叧鑱斾簡<br /> 3.鍦?lt;message>涓嬌鐢?lt;part>璇︾粏鐨勮瀹氫簡message涓唴瀹廣傚叾涓唴瀹圭殑瑙勮寖<type>灝卞拰<types>鑱旂郴璧鋒潵浜?br /> 4.<types>涓昏鏄畾涔変簡鍏蜂綋鐨剆chema<br /> <img src ="http://www.tkk7.com/liuzheng/aggbug/174523.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/liuzheng/" target="_blank">鍒橀摦 </a> 2008-01-11 10:20 <a href="http://www.tkk7.com/liuzheng/articles/174523.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>浣跨敤spring-ws榪涜webservice鏈嶅姟鍣ㄧ鐨勫紑鍙?/title><link>http://www.tkk7.com/liuzheng/articles/170363.html</link><dc:creator>鍒橀摦 </dc:creator><author>鍒橀摦 </author><pubDate>Tue, 25 Dec 2007 09:48:00 GMT</pubDate><guid>http://www.tkk7.com/liuzheng/articles/170363.html</guid><wfw:comment>http://www.tkk7.com/liuzheng/comments/170363.html</wfw:comment><comments>http://www.tkk7.com/liuzheng/articles/170363.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/liuzheng/comments/commentRss/170363.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/liuzheng/services/trackbacks/170363.html</trackback:ping><description><![CDATA[Spring Web Services offer another endpoint with which you can aggregate multiple handling into one<br /> controller, thus grouping functionality together. This model is based on annotations, so you can use it only with<br /> Java 5 and higher. Here is an example that uses the same marshalled objects as above:<br /> package samples;<br /> import org.springframework.ws.server.endpoint.annotation.Endpoint;<br /> import org.springframework.ws.server.endpoint.annotation.PayloadRoot;<br /> @Endpoint<br /> public class AnnotationOrderEndpoint {<br />     private final OrderService orderService;<br />     public AnnotationOrderEndpoint(OrderService orderService) {<br />     this.orderService = orderService;<br />     }<br />     @PayloadRoot(localPart = "orderRequest", namespace = "http://samples")<br />     public Order getOrder(OrderRequest orderRequest) {<br />     return orderService.getOrder(orderRequest.getId());<br />     }<br />     @PayloadRoot(localPart = "order", namespace = "http://samples")<br />     public void order(Order order) {<br />     orderService.createOrder(order);<br />     }<br /> }<br /> By annotating the class with @Endpoint, you mark it as a Spring-WS endpoint. Because the endpoint class can<br /> have multiple request handling methods, we need to instruct Spring-WS which method to invoke for which<br /> request. This is done using the @PayloadRoot annotation: the getOrder method will be invoked for requests<br /> with a orderRequest local name and a http://samples namespace URI; the order method for requests with a<br /> order local name. For more information about these annotations, refer to Section 5.4.3,<br /> “MethodEndpointMapping”. <p><br />  </p> <p><?xml version="1.0" encoding="UTF-8"?><br /> <beans xmlns="http://www.springframework.org/schema/beans"<br />  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"></p> <p> <description><br />   This web application context contains Spring-WS beans. The beans<br />   defined in this context are automatically detected by Spring-WS,<br />   similar to the way Controllers are picked up in Spring Web MVC.<br />  </description></p> <p> <bean<br />   class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"><br />   <description><br />    Detects @PayloadRoot annotations on @Endpoint bean methods.<br />    The MarshallingAirlineEndpoint has such annotations. It uses<br />    two interceptors: one that logs the message payload, and the<br />    other validates it accoring to the 'airline.xsd' schema<br />    file.<br />   </description><br />  </bean><br />  <bean id="echo"<br />   class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition"><br />   <description><br />    This bean definition represents a WSDL definition that is<br />    generated at runtime, based on the builder defined below. It<br />    can be retrieved by going to /echo/echo.wsdl (i.e. the bean<br />    name corresponds to the filename).<br />   </description><br />   <property name="builder"><br />    <description><br />     The builder creates a WSDL from the 'echo.xsd' schema.<br />     It detects all elements that ends with 'Request', finds<br />     corresponding 'Response' messages, and creates an<br />     operation based on that. All operations are put in a<br />     portType with name 'Echo', and binding and service are<br />     created.<br />    </description><br />    <bean<br />     class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder"><br />     <property name="schema" value="/WEB-INF/echo.xsd" /><br />     <property name="portTypeName" value="Echo" /><br />     <property name="locationUri"<br />      value="http://localhost:8080/echoweb/services" /><br />    </bean><br />   </property><br />  </bean><br />  <bean id="echoEndpoint" class="com.vanad.EchoEndpoint"><br />   <description>This endpoint handles echo requests.</description><br />   <property name="echoService" ref="echoService" /><br />  </bean><br />  <bean id="echoService" class="com.vanad.EchoServiceImpl"><br />   <description>This bean is our "business" service.</description><br />  </bean></p> <p> <bean id="payloadLoggingInterceptor"<br />   class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"><br />  </bean></p> <p> <bean id="soapEnvelopeLoggingInterceptor"<br />   class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor"><br />  </bean><br />  <bean<br />   class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter"><br />   <constructor-arg ref="marshaller" /><br />  </bean><br />  <bean id="marshaller"<br />   class="org.springframework.oxm.jaxb.Jaxb2Marshaller"><br />   <property name="contextPath" value="com.vanad.schema" /><br />  </bean><br /> </beans></p> <p><br />  </p> 涔熷氨鏄鐢╯pring寮鍙憌ebservice闇瑕侀厤緗竴涓嬫枃浠訛細<br /> 1.EndPoint錛屽鏋滀嬌鐢ㄦ爣璁扮殑璇濓紝灝卞彲浠ヤ笉鐢ㄧ戶鎵夸換浣曠被<br /> 2.EndpointMapping錛孌etects @PayloadRoot annotations on @Endpoint bean methods.<br /> 3.DynamicWsdl11Definition銆傚姩鎬佺敓鎴怶SDL<br /> 濡傛灉浣跨敤JAXB浣滀負Object鍜孹ML鐨勬槧灝勶紝閭d箞榪橀渶瑕?br /> 4.Marshaller涓鑸負Jaxb2Marshaller<br /> 5.濡傛灉鏄嬌鐢ㄧ殑鏍囪鐨勮瘽錛岃繕闇瑕丮arshallingMethodEndpointAdapter錛屼竴鑸幇鍦ㄤ嬌鐢?br />     GenericMarshallingMethodEndpointAdapter <img src ="http://www.tkk7.com/liuzheng/aggbug/170363.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/liuzheng/" target="_blank">鍒橀摦 </a> 2007-12-25 17:48 <a href="http://www.tkk7.com/liuzheng/articles/170363.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>浣跨敤SAAJ鐨勫瓙鍏冪礌鐨勬坊鍔?/title><link>http://www.tkk7.com/liuzheng/articles/168406.html</link><dc:creator>鍒橀摦 </dc:creator><author>鍒橀摦 </author><pubDate>Tue, 18 Dec 2007 02:14:00 GMT</pubDate><guid>http://www.tkk7.com/liuzheng/articles/168406.html</guid><wfw:comment>http://www.tkk7.com/liuzheng/comments/168406.html</wfw:comment><comments>http://www.tkk7.com/liuzheng/articles/168406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/liuzheng/comments/commentRss/168406.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/liuzheng/services/trackbacks/168406.html</trackback:ping><description><![CDATA[private void handleBookListRequest(SOAPBody replyBody) throws SOAPException {<br />         // Create a BookTitles element containing an entry<br />         // for each book title.<br />        <span style="color: red"> SOAPBodyElement bodyElement = replyBody.addBodyElement(BOOK_TITLES_NAME);<br /> </span>        <br />         // Add 'xsi:type = "SOAP-ENC:Array"'<br />         bodyElement.addAttribute(<br />             soapFactory.createName("type", XMLSCHEMA_INSTANCE_PREFIX, <br />                 XMLSCHEMA_INSTANCE_URI), SOAP_ENC_PREFIX + ":Array");<br />         <br />         // Add 'SOAP-ENC:arrayType = "xsd:string[]"<br />         bodyElement.addAttribute(<br />             soapFactory.createName("arrayType", SOAP_ENC_PREFIX, <br />                 SOAPConstants.URI_NS_SOAP_ENCODING), XMLSCHEMA_PREFIX +<br />                 ":string[]");<br />         <br />         // Add an array entry for each book <br />         String[] titles = BookImageServletData.getBookTitles(  );<br />         for (int i = 0; i < titles.length; i++) {<br />             SOAPElement titleElement = <span style="color: red">bodyElement</span>.addChildElement("item");<br />             titleElement.addTextNode(titles[i]);<br />         }        <br />     }<br /> <br /> 娉ㄦ剰綰㈣壊瀛椾綋錛宎ddChildElement <dt><strong>榪斿洖錛?/strong> <dd>涓涓疄渚嬶紝琛ㄧず瀹為檯娣誨姞鍒版爲鐨勬柊 SOAP 鍏冪礌銆?/dd> <dt>浠ュ悗瑕佷嬌鐢?span style="color: red">bodyElement鎵嶈兘娣誨姞浠栫殑瀛愬厓绱狅紝浠庤屽艦鎴愭爲銆?/span></dt> <img src ="http://www.tkk7.com/liuzheng/aggbug/168406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/liuzheng/" target="_blank">鍒橀摦 </a> 2007-12-18 10:14 <a href="http://www.tkk7.com/liuzheng/articles/168406.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>浣跨敤SAAJ澶勭悊SOAPhttp://www.tkk7.com/liuzheng/articles/168276.html鍒橀摦 鍒橀摦 Mon, 17 Dec 2007 09:27:00 GMThttp://www.tkk7.com/liuzheng/articles/168276.htmlhttp://www.tkk7.com/liuzheng/comments/168276.htmlhttp://www.tkk7.com/liuzheng/articles/168276.html#Feedback0http://www.tkk7.com/liuzheng/comments/commentRss/168276.htmlhttp://www.tkk7.com/liuzheng/services/trackbacks/168276.htmlThe foundation of Web services lies in the sending and receiving of messages in a standard format so that all systems can understand them. Typically, that format is SOAP. A SOAP message can be generated and sent manually, but the SOAP with Attachments API for Java (SAAJ) -- an offshoot of the Java API for XML Messaging (JAXM) -- automates many of the required steps, such as creating connections or creating and sending the actual messages. This tip chronicles the creation and sending of a synchronous SOAP message.

The process involves five steps:

  1. Creating a SOAP connection
  2. Creating a SOAP message
  3. Populating the message
  4. Sending the message
  5. Retrieving the reply

SAAJ is available as part of the Java Web Services Developer Pack 1.2 (see Resources). This package also includes a copy of the Tomcat Web server (so you can host your own service) and sample applications.


The structure of a SOAP message

I'll start by showing you the structure of the message itself. A basic SOAP message consists of an envelope with two main parts: the header and the body. The application determines how these parts are used, but the overall message must follow a specific XML structure, such as:


Listing 1. A sample SOAP message
				<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
            xmlns:xsd="http://www.w3.org/1999/XMLSchema">
            <SOAP-ENV:Header />
            <SOAP-ENV:Body> 
            <ns1:getPrice xmlns:ns1="urn:xmethods-BNPriceCheck"
            SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <isbn xsi:type="xsd:string">0672324229</isbn>
            </ns1:getPrice>
                </SOAP-ENV:Body>
            </SOAP-ENV:Envelope> 
            

Here, the header is empty and the body contains the payload, or the message to be delivered. In this case, it's a message requesting the price of a book.

Notice the structure of the message. The Envelope contains the Header and Body elements, and all three are part of the http://schemas.xmlsoap.org/soap/envelope/ namespace. The application sends the message using a SOAPConnection.




Creating the connection and the message

The first step is to create the overall class and the connection:


Listing 2. Create the connection
import javax.xml.soap.SOAPConnectionFactory;
            import javax.xml.soap.SOAPConnection;
            public class SOAPTip {
            public static void main(String args[]) {
            try {
                     //First create the connection
            SOAPConnectionFactory soapConnFactory =
            SOAPConnectionFactory.newInstance();
            SOAPConnection connection =
            soapConnFactory.createConnection();
            //Close the connection
            connection.close();
            } catch(Exception e) {
            System.out.println(e.getMessage());
            }
            }
            }

The application can send SOAP messages directly using a SOAPConnection, which is now part of the SAAJ package, or indirectly using a messaging provider, which remains in the JAXM package. In this case, the application creates the SOAPConnection object using a factory.

A factory also creates the message itself:


Listing 3. Creating the message object
import javax.xml.soap.SOAPConnectionFactory;
            import javax.xml.soap.SOAPConnection;
            import javax.xml.soap.MessageFactory;
            import javax.xml.soap.SOAPMessage;
            import javax.xml.soap.SOAPPart;
            import javax.xml.soap.SOAPEnvelope;
            import javax.xml.soap.SOAPBody;
            public class SOAPTip {
            public static void main(String args[]) {
            try {
            //First create the connection
            SOAPConnectionFactory soapConnFactory =
            SOAPConnectionFactory.newInstance();
            SOAPConnection connection =
            soapConnFactory.createConnection();
                    //Next, create the actual message
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            //Create objects for the message parts
            SOAPPart soapPart =     message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            SOAPBody body =         envelope.getBody();
            //Close the connection
            connection.close();
            } catch(Exception e) {
            System.out.println(e.getMessage());
            }
            }
            }

Version differences
If you've using another version of SAAJ, such as the Axis 1.2 beta SAAJ library, you may need to use addBodyElement instead of addChildElement.

First, you create the message itself by using the MessageFactory. This message already contains empty versions of the basic parts, such as the envelope and header. The SOAPPart contains the envelope, and the envelope contains the body. Create references to the needed objects, such as the SOAPBody.

Next, populate the SOAPBody:


Listing 4. Populating the body
...
            import javax.xml.soap.SOAPBody;
            import javax.xml.soap.SOAPElement;
            public class SOAPTip {
            public static void main(String args[]) {
            try {
            ...
            //Create objects for the message parts
            SOAPPart soapPart =     message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            SOAPBody body =         envelope.getBody();
                    //Populate the body
            //Create the main element and namespace
            SOAPElement bodyElement =
            body.addChildElement(envelope.createName("getPrice" ,
            "ns1",
            "urn:xmethods-BNPriceCheck"));
            //Add content
            bodyElement.addChildElement("isbn").addTextNode("0672324229");
            //Save the message
            message.saveChanges();
            //Check the input
            System.out.println("\nREQUEST:\n");
            message.writeTo(System.out);
            System.out.println();
            //Close the connection
            connection.close();
            } catch(Exception e) {
            System.out.println(e.getMessage());
            }
            }
            }

The body of the SOAP message is just like any other XML element in that you can add a child element, such as getPrice. You can then add the isbn element and its text node just as you might with a typical DOM element.

With SAAJ you also have the opportunity to directly create the SOAPPart of the message using an external file. For example, the file prepped.msg contains the XML structure in the first listing, and can be called in lieu of building the document manually:


Listing 5. Creating the message from an external file
...
            import javax.xml.soap.SOAPElement;
            import java.io.FileInputStream;
            import javax.xml.transform.stream.StreamSource;
            public class SOAPTip {
            public static void main(String args[]) {
            ...
            //Create objects for the message parts
            SOAPPart soapPart =     message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            SOAPBody body =         envelope.getBody();
            //Populate the Message
            StreamSource preppedMsgSrc = new StreamSource(
            new FileInputStream("prepped.msg"));
            soapPart.setContent(preppedMsgSrc);
            //Save the message
            message.saveChanges();
            ...
            }
            }

The StreamSource class is typically used as part of an XSL Transformation, but here you can use it simply to obtain the FileInputStream. The result is a SOAP message that's ready to send.




Sending the message

With a synchronous message, sending the SOAP message and receiving a reply take place in a single step:


Listing 6. Sending the message
...
            public class SOAPTip {
            public static void main(String args[]) {
            ...
            //Check the input
            System.out.println("\nREQUEST:\n");
            message.writeTo(System.out);
            System.out.println();
                    //Send the message and get a reply
            //Set the destination
            String destination =
            "http://services.xmethods.net:80/soap/servlet/rpcrouter";
            //Send the message
            SOAPMessage reply = connection.call(message, destination);
            //Close the connection
            connection.close();
            ...
            }
            }

The actual message is sent using the call() method, which takes the message itself and a destination as arguments and returns a second SOAPMessage as a reply. In earlier versions of JAXM, the destination had to be an Endpoint object or a URLEndpoint, but now it simply has to be an object. This example uses the "Book price checker" Web service hosted by XMethods, which returns the price of the book whose ISBN is listed in the request.

The call() method blocks until it receives the returned SOAPMessage.




The response

The returned SOAPMessage, reply, is a SOAP message in the same form as the message sent, and as such can be manipulated just like any other XML message. SOAP allows you to transform the reply directly using XSLT:


Listing 7. Reading the response
...
            import javax.xml.transform.TransformerFactory;
            import javax.xml.transform.Transformer;
            import javax.xml.transform.Source;
            import javax.xml.transform.stream.StreamResult;
            public class SOAPTip {
            public static void main(String args[]) {
            try {
            ...
            //Send the message
            SOAPMessage reply = connection.call(message, destination);
                    //Check the output
            System.out.println("\nRESPONSE:\n");
            //Create the transformer
            TransformerFactory transformerFactory =
            TransformerFactory.newInstance();
            Transformer transformer =
            transformerFactory.newTransformer();
            //Extract the content of the reply
            Source sourceContent = reply.getSOAPPart().getContent();
            //Set the output for the transformation
            StreamResult result = new StreamResult(System.out);
            transformer.transform(sourceContent, result);
            System.out.println();
            //Close the connection
            connection.close();
            ...
            }
            }

Create the Transformer object as you would in any XSLT application. In this case, you just want to output the content, so there's no stylesheet. Here, the content itself is the entire SOAP part of the message (as opposed to the SOAP message itself, which might include attachments). You could also extract the envelope and body before processing. The result in this case is simply System.out, but can be any choice normally available to a transformation. Transform as usual.



]]>
主站蜘蛛池模板: 亚欧国产一级在线免费| 久久99精品视免费看| 久久九九免费高清视频| 最近中文字幕免费mv在线视频| 四虎影在线永久免费四虎地址8848aa| 亚洲国产精品无码专区在线观看 | 成年人免费网站在线观看| 91亚洲精品麻豆| 亚洲成人免费在线观看| 国产人妖ts在线观看免费视频| 亚洲人片在线观看天堂无码| 无码人妻精品中文字幕免费| 亚洲综合自拍成人| 国产一卡2卡3卡4卡2021免费观看 国产一卡2卡3卡4卡无卡免费视频 | 国产成人亚洲综合在线| 久久99国产综合精品免费| 少妇中文字幕乱码亚洲影视| 99在线观看免费视频| 亚洲国产日产无码精品| 国产成人免费爽爽爽视频| 久久国产亚洲电影天堂| 成人午夜影视全部免费看| 亚洲免费无码在线| 99精品热线在线观看免费视频| 亚洲精品成人久久| 国产美女无遮挡免费视频| 激情综合亚洲色婷婷五月| 免费无码又爽又刺激高潮| 一本到卡二卡三卡免费高| 亚洲Av无码国产情品久久| 国产精品综合专区中文字幕免费播放 | 久久精品熟女亚洲av麻豆| 国产国拍亚洲精品福利 | 波多野结衣免费视频观看| 青青操在线免费观看| 亚洲国产av一区二区三区丶| 国产一级一片免费播放| 1a级毛片免费观看| 色屁屁在线观看视频免费| 久久青青草原亚洲av无码app| 精品免费国产一区二区三区 |