Source Code Cross Referenced for AddNumbersClientLogicalHandler.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » sample » addnumbershandler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » jax ws » org.apache.axis2.jaxws.sample.addnumbershandler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.jaxws.sample.addnumbershandler;
020:
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.StringBufferInputStream;
023:        import java.util.Map;
024:        import java.util.StringTokenizer;
025:
026:        import javax.xml.transform.OutputKeys;
027:        import javax.xml.transform.Source;
028:        import javax.xml.transform.Transformer;
029:        import javax.xml.transform.TransformerFactory;
030:        import javax.xml.transform.stream.StreamResult;
031:        import javax.xml.transform.stream.StreamSource;
032:        import javax.xml.ws.LogicalMessage;
033:        import javax.xml.ws.ProtocolException;
034:        import javax.xml.ws.handler.MessageContext;
035:
036:        import org.apache.axis2.jaxws.handler.AttachmentsAdapter;
037:        import org.apache.axis2.jaxws.handler.LogicalMessageContext;
038:
039:        /*
040:         * You can't actually specify whether a handler is for client or server,
041:         * you just have to check in the handleMessage and/or handleFault to make
042:         * sure what direction we're going.
043:         */
044:
045:        public class AddNumbersClientLogicalHandler implements 
046:                javax.xml.ws.handler.LogicalHandler<LogicalMessageContext> {
047:
048:            public void close(MessageContext messagecontext) {
049:            }
050:
051:            public boolean handleFault(LogicalMessageContext messagecontext) {
052:                return true;
053:            }
054:
055:            public boolean handleMessage(LogicalMessageContext messagecontext) {
056:                Boolean outbound = (Boolean) messagecontext
057:                        .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
058:                if (!outbound) { // inbound response on the client
059:
060:                    // make sure standard property is available
061:
062:                    Object bob = messagecontext
063:                            .get(LogicalMessageContext.HTTP_RESPONSE_CODE);
064:                    if (bob == null) {
065:                        throw new NullPointerException("bob is null");
066:                    }
067:
068:                    // previously caused a NPE due to internal Properties.putAll(map);
069:                    // where 'map' had a key/value pair with null value.  So, internally
070:                    // we now use HashMap instead of Properties.
071:                    int size = messagecontext.size();
072:
073:                    /*
074:                     * These props were set on the outbound flow.  Inbound flow handlers
075:                     * should have access to them.
076:                     */
077:                    String propKey = "AddNumbersClientProtocolHandlerOutboundAppScopedProperty";
078:                    String myClientVal = (String) messagecontext.get(propKey);
079:                    if (myClientVal == null) {
080:                        throw new RuntimeException(
081:                                "Property "
082:                                        + propKey
083:                                        + " was null.  "
084:                                        + "MEPContext is not searching hard enough for the property.");
085:                    }
086:
087:                    // Check for the presences of the attachment property
088:                    propKey = MessageContext.INBOUND_MESSAGE_ATTACHMENTS;
089:                    Map map = (Map) messagecontext.get(propKey);
090:                    if (map == null) {
091:                        throw new RuntimeException("Property " + propKey
092:                                + " was null");
093:                    }
094:                    if (!(map instanceof  AttachmentsAdapter)) {
095:                        throw new RuntimeException(
096:                                "Expected AttachmentAddapter for Property "
097:                                        + propKey);
098:                    }
099:                    propKey = "AddNumbersClientProtocolHandlerOutboundHandlerScopedProperty";
100:                    myClientVal = (String) messagecontext.get(propKey);
101:                    if (myClientVal == null) {
102:                        throw new RuntimeException(
103:                                "Property "
104:                                        + propKey
105:                                        + " was null.  "
106:                                        + "MEPContext is not searching hard enough for the property.");
107:                    }
108:
109:                    /*
110:                     * These props were set on the inbound flow.  Inbound flow handlers
111:                     * should have access to them.
112:                     */
113:                    propKey = "AddNumbersClientProtocolHandlerInboundAppScopedProperty";
114:                    myClientVal = (String) messagecontext.get(propKey);
115:                    if (myClientVal == null) {
116:                        throw new RuntimeException(
117:                                "Property "
118:                                        + propKey
119:                                        + " was null.  "
120:                                        + "MEPContext is not searching hard enough for the property.");
121:                    }
122:                    propKey = "AddNumbersClientProtocolHandlerInboundHandlerScopedProperty";
123:                    myClientVal = (String) messagecontext.get(propKey);
124:                    if (myClientVal == null) {
125:                        throw new RuntimeException(
126:                                "Property "
127:                                        + propKey
128:                                        + " was null.  "
129:                                        + "MEPContext is not searching hard enough for the property.");
130:                    }
131:                    LogicalMessage msg = messagecontext.getMessage();
132:                    String st = getStringFromSourcePayload(msg.getPayload());
133:                    String txt = String.valueOf(Integer
134:                            .valueOf(getFirstArg(st)) - 1);
135:                    st = replaceFirstArg(st, txt);
136:                    msg.setPayload(new StreamSource(
137:                            new StringBufferInputStream(st)));
138:                } else {
139:                    LogicalMessage msg = messagecontext.getMessage();
140:
141:                    Source s = msg.getPayload();
142:                    s = msg.getPayload();
143:
144:                    String st = getStringFromSourcePayload(msg.getPayload());
145:                    if (st.contains("<arg0>99</arg0>")) {
146:                        throw new ProtocolException("I don't like the value 99");
147:                    }
148:
149:                    // Check for the presences of the attachment property
150:                    String propKey = MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS;
151:                    Map map = (Map) messagecontext.get(propKey);
152:                    if (map == null) {
153:                        throw new RuntimeException("Property " + propKey
154:                                + " was null");
155:                    }
156:                    if (!(map instanceof  AttachmentsAdapter)) {
157:                        throw new RuntimeException(
158:                                "Expected AttachmentAddapter for Property "
159:                                        + propKey);
160:                    }
161:                }
162:                return true;
163:            }
164:
165:            private static String getFirstArg(String payloadString) {
166:                StringTokenizer st = new StringTokenizer(payloadString, ">");
167:                st.nextToken(); // skip first token.
168:                st.nextToken(); // skip second
169:                String tempString = st.nextToken();
170:                String returnString = new StringTokenizer(tempString, "<")
171:                        .nextToken();
172:                return returnString;
173:            }
174:
175:            private static String replaceFirstArg(String payloadString,
176:                    String newArg) {
177:                String firstArg = getFirstArg(payloadString);
178:                payloadString = payloadString.replaceFirst(firstArg, newArg);
179:                return payloadString;
180:            }
181:
182:            private static String getStringFromSourcePayload(Source payload) {
183:                try {
184:
185:                    TransformerFactory factory = TransformerFactory
186:                            .newInstance();
187:                    Transformer trans = factory.newTransformer();
188:
189:                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
190:                    StreamResult result = new StreamResult(baos);
191:
192:                    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
193:                            "yes");
194:                    trans.transform(payload, result);
195:
196:                    return new String(baos.toByteArray());
197:                } catch (Exception e) {
198:                    throw new RuntimeException(e);
199:                }
200:
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.