KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > jbws83 > ClientHandler


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.webservice.jbws83;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import javax.xml.rpc.handler.GenericHandler JavaDoc;
26 import javax.xml.rpc.handler.MessageContext JavaDoc;
27 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
28 import javax.xml.soap.SOAPException JavaDoc;
29 import javax.xml.soap.SOAPMessage JavaDoc;
30
31 import org.jboss.logging.Logger;
32
33 import java.io.ByteArrayOutputStream JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 public class ClientHandler extends GenericHandler JavaDoc
37 {
38    // provide logging
39
private static final Logger log = Logger.getLogger(ClientHandler.class);
40    
41    protected QName JavaDoc[] headers;
42
43    public QName JavaDoc[] getHeaders()
44    {
45       return headers;
46    }
47
48    public boolean handleRequest(MessageContext JavaDoc msgContext)
49    {
50       try
51       {
52          processMessage(msgContext);
53          return true;
54       }
55       catch (RuntimeException JavaDoc rte)
56       {
57          throw rte;
58       }
59       catch (Exception JavaDoc e)
60       {
61          throw new IllegalArgumentException JavaDoc(e.toString());
62       }
63    }
64
65    public boolean handleResponse(MessageContext JavaDoc msgContext)
66    {
67       try
68       {
69          processMessage(msgContext);
70          return true;
71       }
72       catch (RuntimeException JavaDoc rte)
73       {
74          throw rte;
75       }
76       catch (Exception JavaDoc e)
77       {
78          throw new IllegalArgumentException JavaDoc(e.toString());
79       }
80    }
81
82    /** Process request/response message
83     */

84    private void processMessage(MessageContext JavaDoc msgContext) throws SOAPException JavaDoc, IOException JavaDoc
85    {
86       SOAPMessageContext JavaDoc soapContext = (SOAPMessageContext JavaDoc)msgContext;
87       SOAPMessage JavaDoc soapMessage = soapContext.getMessage();
88
89       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
90       soapMessage.writeTo(baos);
91       String JavaDoc msgStr = new String JavaDoc(baos.toByteArray());
92
93       log.debug(msgStr);
94
95       String JavaDoc expElement = "<my-msg>Kermit</my-msg>";
96       if (msgStr.indexOf(expElement) < 0)
97          throw new SOAPException JavaDoc("Cannot find " + expElement + " in SOAPMessage");
98    }
99 }
100
Popular Tags