Source Code Cross Referenced for SOAPRequestProcessor.java in  » Portal » stringbeans-3.5 » com » nabhinc » ws » soap » 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 » Portal » stringbeans 3.5 » com.nabhinc.ws.soap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        /*
018:         * Modified by Nabh Information Systems, Inc. for Stringbeans Web Services
019:         * Framework.
020:         * 
021:         * Modifications (c) 2005 Nabh Information Systems, Inc.
022:         */
023:
024:        package com.nabhinc.ws.soap;
025:
026:        import java.io.IOException;
027:        import java.io.Writer;
028:        import java.util.Enumeration;
029:        import java.util.HashMap;
030:        import java.util.Iterator;
031:
032:        import javax.servlet.ServletException;
033:        import javax.servlet.http.HttpServletRequest;
034:        import javax.servlet.http.HttpServletResponse;
035:        import javax.servlet.http.HttpUtils;
036:        import javax.wsdl.OperationType;
037:        import javax.xml.soap.MimeHeader;
038:        import javax.xml.soap.MimeHeaders;
039:        import javax.xml.soap.SOAPException;
040:        import javax.xml.soap.SOAPMessage;
041:
042:        import org.apache.axis.AxisEngine;
043:        import org.apache.axis.AxisFault;
044:        import org.apache.axis.Message;
045:        import org.apache.axis.MessageContext;
046:        import org.apache.axis.constants.Style;
047:        import org.apache.axis.description.OperationDesc;
048:        import org.apache.axis.handlers.soap.SOAPService;
049:        import org.apache.axis.message.SOAPEnvelope;
050:        import org.apache.axis.soap.SOAPConstants;
051:        import org.apache.axis.transport.http.AxisHttpSession;
052:        import org.apache.axis.transport.http.HTTPConstants;
053:        import org.apache.axis.utils.Messages;
054:        import org.apache.axis.utils.XMLUtils;
055:        import org.w3c.dom.Document;
056:        import org.w3c.dom.Element;
057:
058:        import com.nabhinc.util.DOM2Writer;
059:        import com.nabhinc.util.XMLUtil;
060:        import com.nabhinc.ws.core.UnavailableException;
061:        import com.nabhinc.ws.core.WebServiceException;
062:        import com.nabhinc.ws.core.WebServiceSecurityException;
063:        import com.nabhinc.ws.server.InterceptorChain;
064:        import com.nabhinc.ws.server.InterceptorInfo;
065:        import com.nabhinc.ws.server.InterceptorManager;
066:        import com.nabhinc.ws.server.RequestInfo;
067:        import com.nabhinc.ws.server.ServerObjectConfig;
068:        import com.nabhinc.ws.server.ServerObjectImpl;
069:        import com.nabhinc.ws.server.ServletRequestProcessor;
070:        import com.nabhinc.ws.server.WebServiceInfo;
071:        import com.nabhinc.ws.server.WebServiceServerConstants;
072:
073:        /**
074:         * SOAP-based request processor
075:         * 
076:         * @author Padmanabh Dabke
077:         * (c) 2005 Nabh Information Systems, Inc.
078:         */
079:        public class SOAPRequestProcessor extends ServerObjectImpl implements 
080:                ServletRequestProcessor {
081:
082:            private static SOAPRequestProcessor srpSelf = null;
083:
084:            private AxisServlet srpAxisServlet = null;
085:
086:            private HashMap srpServices = new HashMap();
087:
088:            private RPCProvider srpRPCProvider = new RPCProvider();
089:
090:            private MsgProvider srpMsgProvider = new MsgProvider();
091:
092:            private WSDLProcessor srpWSDLProcessor = new WSDLProcessor(this );
093:
094:            protected static SOAPRequestProcessor getInstance() {
095:                return srpSelf;
096:            }
097:
098:            /*
099:             * (non-Javadoc)
100:             * 
101:             * @see com.nabhinc.ws.server.RequestProcessor#init(com.nabhinc.ws.server.WebServiceContext,
102:             *      com.nabhinc.core.PropertiesInfo[])
103:             */
104:            public void init(ServerObjectConfig config)
105:                    throws WebServiceException {
106:                srpSelf = this ;
107:                super .init(config);
108:                srpAxisServlet = new AxisServlet();
109:                try {
110:
111:                    srpAxisServlet.init(config.getWebServiceContext()
112:                            .getServletConfig());
113:                    srpAxisServlet.getEngine();
114:                    // TypeMappingRegistry tmr =
115:                    // engine.getConfig().getTypeMappingRegistry();
116:
117:                } catch (AxisFault ex) {
118:                    throw new WebServiceException("Failed to get Axis engine.",
119:                            ex);
120:                } catch (ServletException ex) {
121:                    throw new WebServiceException(ex.getMessage(), ex
122:                            .getRootCause());
123:                }
124:            }
125:
126:            public void processError(HttpServletRequest req,
127:                    HttpServletResponse resp, String msg) throws IOException {
128:
129:                AxisFault fault = new AxisFault(msg);
130:                srpAxisServlet.processAxisFault(fault);
131:                srpAxisServlet.configureResponseFromAxisFault(resp, fault);
132:                Message responseMsg = new Message(fault);
133:                srpAxisServlet.sendResponse("text/xml", resp, responseMsg);
134:
135:            }
136:
137:            /*
138:             * (non-Javadoc)
139:             * 
140:             * @see com.nabhinc.ws.server.RequestProcessor#process(javax.servlet.http.HttpServletRequest,
141:             *      javax.servlet.http.HttpServletResponse,
142:             *      com.nabhinc.ws.server.RequestInfo,
143:             *      com.nabhinc.ws.server.WebServiceInfo)
144:             */
145:            public void process(HttpServletRequest req,
146:                    HttpServletResponse res, RequestInfo reqInfo)
147:                    throws ServletException, IOException {
148:
149:                WebServiceInfo serviceInfo = reqInfo.serviceInfo;
150:                Message responseMsg = null;
151:                String contentType = null;
152:                MessageContext msgContext = null;
153:                MessageContext prevContext = AxisEngine
154:                        .getCurrentMessageContext();
155:                try {
156:                    AxisEngine engine = srpAxisServlet.getEngine();
157:                    if (engine == null) {
158:                        ServletException se = new ServletException(Messages
159:                                .getMessage("noEngine00"));
160:                        throw se;
161:                    }
162:
163:                    res.setBufferSize(1024 * 8); // provide performance boost.
164:
165:                    msgContext = srpAxisServlet.createMessageContext(engine,
166:                            req, res);
167:
168:                    // Get a reference to Axis SOAPService that has the service
169:                    // description and type mapping information. We first try to
170:                    // get it from AxisEngine. We will get a non-null reference
171:                    // if this service was included in Axis deployment descriptor
172:                    // file "server-config.wsdd". If it is not found there, we
173:                    // check to see if we have a cached reference. If nothing works
174:                    // out we create a new instance and cache it.
175:
176:                    // SOAPService service = engine.getService(serviceInfo.name);
177:                    // if (service == null) {
178:                    SOAPService service = (SOAPService) srpServices
179:                            .get(serviceInfo.name);
180:                    // }
181:                    // if (service == null) {
182:                    // service = createService(serviceInfo, msgContext);
183:                    // }
184:
185:                    msgContext.setService(service);
186:
187:                    /*
188:                     * Get request message
189:                     */
190:                    Message requestMsg = new Message(
191:                            req.getInputStream(),
192:                            false,
193:                            req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE),
194:                            req
195:                                    .getHeader(HTTPConstants.HEADER_CONTENT_LOCATION));
196:                    // Transfer HTTP headers to MIME headers for request message.
197:                    MimeHeaders requestMimeHeaders = requestMsg
198:                            .getMimeHeaders();
199:                    for (Enumeration e = req.getHeaderNames(); e
200:                            .hasMoreElements();) {
201:                        String headerName = (String) e.nextElement();
202:                        for (Enumeration f = req.getHeaders(headerName); f
203:                                .hasMoreElements();) {
204:                            String headerValue = (String) f.nextElement();
205:                            requestMimeHeaders.addHeader(headerName,
206:                                    headerValue);
207:                        }
208:                    }
209:                    msgContext.setRequestMessage(requestMsg);
210:
211:                    String url = HttpUtils.getRequestURL(req).toString();
212:                    msgContext.setProperty(MessageContext.TRANS_URL, url);
213:                    // put character encoding of request to message context
214:                    // in order to reuse it during the whole process.
215:                    String requestEncoding;
216:                    try {
217:                        requestEncoding = (String) requestMsg
218:                                .getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
219:                        if (requestEncoding != null) {
220:                            msgContext.setProperty(
221:                                    SOAPMessage.CHARACTER_SET_ENCODING,
222:                                    requestEncoding);
223:                        }
224:                    } catch (SOAPException e1) {
225:                    }
226:
227:                    /**
228:                     * Save the SOAPAction header in the MessageContext bag. This will
229:                     * be used to tell the Axis Engine which service is being invoked.
230:                     * This will save us the trouble of having to parse the Request
231:                     * message - although we will need to double-check later on that the
232:                     * SOAPAction header does in fact match the URI in the body.
233:                     */
234:                    // (is this last stmt true??? (I don't think so - Glen))
235:                    /** ***************************************************** */
236:                    String soapAction = srpAxisServlet.getSoapAction(req);
237:
238:                    if (soapAction != null) {
239:                        msgContext.setUseSOAPAction(true);
240:                        msgContext.setSOAPActionURI(soapAction);
241:                    }
242:
243:                    // Create a Session wrapper for the HTTP session.
244:                    // These can/should be pooled at some point.
245:                    // (Sam is Watching! :-)
246:                    msgContext.setSession(new AxisHttpSession(req));
247:
248:                    /* Invoke the Axis engine... */
249:                    /** ************************** */
250:                    debug("Invoking Axis Engine.");
251:                    StringbeansAxisEngine.setCurrentMessageContext(msgContext);
252:                    // engine.invoke(msgContext);
253:
254:                    // It's possible that we haven't yet parsed the
255:                    // message at this point. This is a kludge to
256:                    // make sure we have. There probably wants to be
257:                    // some kind of declarative "parse point" on the handler
258:                    // chain instead....
259:                    Message reqMsg = msgContext.getRequestMessage();
260:                    reqMsg.getSOAPEnvelope().getFirstBody();
261:                    initSOAPConstants(msgContext);
262:
263:                    // Invoke interceptor chain. At the end of interceptor chain,
264:                    // WebServiceInterceptorChain object will invoke the actual
265:                    // service method.
266:                    InterceptorInfo[] ints = InterceptorManager
267:                            .getInterceptorChain(reqInfo.serviceInfo.name,
268:                                    reqInfo.methodName);
269:                    InterceptorChain chain = new InterceptorChain(ints);
270:                    try {
271:                        chain.doIntercept(reqInfo);
272:                        if (reqInfo.redirect != null) {
273:                            res.sendRedirect(reqInfo.redirect);
274:                            return;
275:                        }
276:                    } catch (WebServiceSecurityException e) {
277:                        res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
278:                    } catch (Throwable t) {
279:                        res
280:                                .setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
281:                    }
282:                    /*
283:                    SOAPEnvelope resEnv = null;
284:                    OperationDesc operation = msgContext.getOperation();
285:                    if (operation != null
286:                    		&& operation.getMep() == OperationType.ONE_WAY) {
287:                    	msgContext.setResponseMessage(null);
288:                    } else {
289:                    	responseMsg = msgContext.getResponseMessage();
290:
291:                    	// If we didn't have a response message, make sure we set one up
292:                    	// with the appropriate versions of SOAP and Schema
293:                    	if (responseMsg == null) {
294:                    		resEnv = new SOAPEnvelope(msgContext.getSOAPConstants(),
295:                    				msgContext.getSchemaVersion());
296:
297:                    		responseMsg = new Message(resEnv);
298:                    		String encoding = XMLUtils.getEncoding(msgContext);
299:                    		try {
300:                    			responseMsg.setProperty(
301:                    					SOAPMessage.CHARACTER_SET_ENCODING, encoding);
302:                    		} catch (SOAPException se) {
303:                    			throw new ServletException(
304:                    					"Failed to set message encoding", se);
305:                    		}
306:                    		msgContext.setResponseMessage(responseMsg);
307:                    	} else {
308:                    		resEnv = responseMsg.getSOAPEnvelope();
309:                    	}
310:                    }
311:
312:                    try {
313:                    	SOAPEnvelope reqEnv = reqMsg.getSOAPEnvelope();
314:                    	// service.invoke(msgContext);
315:                    	if (service.getStyle().equals(Style.MESSAGE)) {
316:                    		srpMsgProvider.processMessage(msgContext, reqEnv, resEnv,
317:                    				reqInfo, chain);
318:                    	} else {
319:                    		srpRPCProvider.processMessage(msgContext, reqEnv, resEnv,
320:                    				reqInfo, chain);
321:                    	}
322:                    	if (reqInfo.redirect != null)
323:                    		return;
324:                    	msgContext.setPastPivot(true);
325:
326:                    	responseMsg = msgContext.getResponseMessage();
327:
328:                    } catch (UnavailableException ex) {
329:                    	reqInfo.serviceInfo.loadError = ex;
330:                    	reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
331:                    	msgContext.setPastPivot(true);
332:                    	AxisFault fault = AxisFault.makeFault(ex);
333:                    	srpAxisServlet.processAxisFault(fault);
334:                    	srpAxisServlet.configureResponseFromAxisFault(res, fault);
335:                    	// responseMsg = msgContext.getResponseMessage();
336:                    	// if (responseMsg == null) {
337:                    	responseMsg = new Message(fault);
338:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
339:                    			.setMessageContext(msgContext);
340:                    	// }
341:                    } catch (WebServiceSecurityException ex) {
342:                    	msgContext.setPastPivot(true);
343:                    	AxisFault fault = AxisFault.makeFault(ex);
344:                    	srpAxisServlet.processAxisFault(fault);
345:                    	res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
346:                    	// responseMsg = msgContext.getResponseMessage();
347:                    	// if (responseMsg == null) {
348:                    	responseMsg = new Message(fault);
349:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
350:                    			.setMessageContext(msgContext);
351:                    	// }
352:                    	
353:                    } catch (WebServiceException ex) {
354:                    	Throwable cause = ex;
355:                    	if (ex.getCause() != null) cause = ex.getCause();
356:                    	msgContext.setPastPivot(true);
357:                    	if (cause instanceof Exception) {
358:                    		AxisFault fault = AxisFault.makeFault((Exception) cause);
359:                    		srpAxisServlet.processAxisFault(fault);
360:                    		srpAxisServlet.configureResponseFromAxisFault(res, fault);
361:                    		responseMsg = new Message(fault);
362:                    	} else {
363:                    		reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
364:                    		reqInfo.serviceInfo.loadError = cause;
365:                    		// other exceptions are internal trouble
366:                    		responseMsg = msgContext.getResponseMessage();
367:                    		res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
368:                    		responseMsg = srpAxisServlet.convertExceptionToAxisFault(cause,
369:                    				responseMsg);
370:
371:                    	}
372:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
373:                    			.setMessageContext(msgContext);
374:                    	
375:
376:                    } catch (AxisFault fault) {
377:                    	// log and sanitize
378:                    	msgContext.setPastPivot(true);
379:                    	srpAxisServlet.processAxisFault(fault);
380:                    	srpAxisServlet.configureResponseFromAxisFault(res, fault);
381:                    	// responseMsg = msgContext.getResponseMessage();
382:                    	// if (responseMsg == null) {
383:                    	responseMsg = new Message(fault);
384:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
385:                    			.setMessageContext(msgContext);
386:                    	// }
387:                    } catch (Exception ex) {
388:                    	msgContext.setPastPivot(true);
389:                    	AxisFault fault = AxisFault.makeFault(ex);
390:                    	srpAxisServlet.processAxisFault(fault);
391:                    	srpAxisServlet.configureResponseFromAxisFault(res, fault);
392:                    	// responseMsg = msgContext.getResponseMessage();
393:                    	// if (responseMsg == null) {
394:                    	responseMsg = new Message(fault);
395:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
396:                    			.setMessageContext(msgContext);
397:                    	// }
398:
399:                    } catch (Throwable t) {
400:                    	msgContext.setPastPivot(true);
401:                    	reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
402:                    	reqInfo.serviceInfo.loadError = t;
403:                    	// other exceptions are internal trouble
404:                    	responseMsg = msgContext.getResponseMessage();
405:                    	res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
406:                    	responseMsg = srpAxisServlet.convertExceptionToAxisFault(t,
407:                    			responseMsg);
408:                    	((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage()
409:                    			.setMessageContext(msgContext);
410:                    }
411:                     */
412:
413:                    responseMsg = msgContext.getResponseMessage();
414:
415:                    /* Send response back along the wire... */
416:                    /** ******************************** */
417:                    if (responseMsg != null) {
418:                        // Transfer MIME headers to HTTP headers for response message.
419:                        MimeHeaders responseMimeHeaders = responseMsg
420:                                .getMimeHeaders();
421:                        for (Iterator i = responseMimeHeaders.getAllHeaders(); i
422:                                .hasNext();) {
423:                            MimeHeader responseMimeHeader = (MimeHeader) i
424:                                    .next();
425:                            res.addHeader(responseMimeHeader.getName(),
426:                                    responseMimeHeader.getValue());
427:                        }
428:                        // synchronize the character encoding of request and response
429:                        String responseEncoding = (String) msgContext
430:                                .getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
431:                        if (responseEncoding != null) {
432:                            try {
433:                                responseMsg.setProperty(
434:                                        SOAPMessage.CHARACTER_SET_ENCODING,
435:                                        responseEncoding);
436:                            } catch (SOAPException e) {
437:                            }
438:                        }
439:                        // determine content type from message response
440:                        contentType = responseMsg.getContentType(msgContext
441:                                .getSOAPConstants());
442:                        srpAxisServlet.sendResponse(contentType, res,
443:                                responseMsg);
444:                    } else {
445:                        // No content, so just indicate accepted
446:                        res.setStatus(202);
447:                    }
448:
449:                    // reset last Call object associated with the current thread
450:                    // Service.clearCall();
451:
452:                    debug("Response sent.");
453:                    debug("Exit: doPost()");
454:                } finally {
455:                    StringbeansAxisEngine.setCurrentMessageContext(prevContext);
456:                }
457:
458:            }
459:
460:            private SOAPService createService(WebServiceInfo serviceInfo)
461:                    throws AxisFault, WebServiceException {
462:                Class intfClass = null;
463:                String intfClassName = serviceInfo
464:                        .computeServiceInterfaceClass();
465:                if (intfClassName != null) {
466:                    try {
467:                        intfClass = Class.forName(intfClassName);
468:                    } catch (ClassNotFoundException e) {
469:                        throw new WebServiceException(
470:                                "Invalid web service impl class.", e);
471:                    }
472:                }
473:                if (intfClass == null) {
474:                    throw new WebServiceException(
475:                            "Neither implementation class nor deployment config is known for service "
476:                                    + serviceInfo.name + ".");
477:                }
478:                String serviceName = serviceInfo.name;
479:                SOAPService service = new SOAPService(
480:                        new org.apache.axis.providers.java.RPCProvider());
481:                service.setServiceDescription(new JavaServiceDesc());
482:                service.setName(serviceName);
483:                service
484:                        .setOption(
485:                                org.apache.axis.providers.java.RPCProvider.OPTION_ALLOWEDMETHODS,
486:                                "*");
487:                service
488:                        .setOption(
489:                                org.apache.axis.providers.java.RPCProvider.OPTION_CLASSNAME,
490:                                serviceInfo.webService.getClass().getName());
491:                JavaServiceDesc serviceDescription = (JavaServiceDesc) service
492:                        .getServiceDescription();
493:                serviceDescription.loadServiceDescByIntrospection(intfClass);
494:                // Set engine, which hooks up type mappings.
495:                service.setEngine(srpAxisServlet.getEngine());
496:
497:                service.init(); //              
498:                return service;
499:
500:            }
501:
502:            /**
503:             * Extract ans store soap constants info from the envelope
504:             * 
505:             * @param msgContext
506:             * @throws AxisFault
507:             */
508:            private void initSOAPConstants(MessageContext msgContext)
509:                    throws AxisFault {
510:                Message msg = msgContext.getRequestMessage();
511:                if (msg == null)
512:                    return;
513:                SOAPEnvelope env = msg.getSOAPEnvelope();
514:                if (env == null)
515:                    return;
516:                SOAPConstants constants = env.getSOAPConstants();
517:                if (constants == null)
518:                    return;
519:                // Ensure that if we get SOAP1.2, then reply using SOAP1.2
520:                msgContext.setSOAPConstants(constants);
521:            }
522:
523:            /*
524:             * (non-Javadoc)
525:             * 
526:             * @see com.nabhinc.ws.server.Interceptor#destroy()
527:             */
528:            public void destroy() {
529:                // Nothing to do
530:
531:            }
532:
533:            /*
534:             * (non-Javadoc)
535:             * 
536:             * @see com.nabhinc.ws.server.RequestProcessor#processServiceConfig(java.lang.String,
537:             *      org.w3c.dom.Element)
538:             */
539:            public void load(WebServiceInfo serviceInfo, Element serviceConfig)
540:                    throws WebServiceException {
541:                try {
542:                    //Element serviceElem = XMLUtil.getSubElement(serviceConfig,
543:                    //		"deployment");
544:                    //if (serviceElem != null) {
545:                    Element serviceElem = XMLUtil.getSubElement(serviceConfig,
546:                            "service");
547:                    //}
548:                    if (serviceElem == null) {
549:                        srpServices.put(serviceInfo.name,
550:                                createService(serviceInfo));
551:                    } else {
552:                        WSDDService wsddService = new WSDDService(serviceElem);
553:                        SOAPService service = (SOAPService) wsddService
554:                                .makeNewInstance(srpAxisServlet.getEngine()
555:                                        .getConfig(), serviceInfo.webService,
556:                                        serviceInfo
557:                                                .computeServiceInterfaceClass());
558:                        service.setEngine(srpAxisServlet.getEngine());
559:                        srpServices.put(serviceInfo.name, service);
560:                    }
561:                } catch (Exception ex) {
562:                    ex.printStackTrace();
563:                    throw new WebServiceException(
564:                            "Failed to create SOAP service", ex);
565:                }
566:
567:            }
568:
569:            /*
570:             * (non-Javadoc)
571:             * 
572:             * @see com.nabhinc.ws.server.RequestProcessor#unload(com.nabhinc.ws.server.WebServiceInfo)
573:             */
574:            public void unload(WebServiceInfo serviceInfo) {
575:                srpServices.remove(serviceInfo.name);
576:
577:            }
578:
579:            protected SOAPService getSOAPService(String name) {
580:                return (SOAPService) srpServices.get(name);
581:            }
582:
583:            public Document getWSDL(WebServiceInfo serviceInfo,
584:                    String serverURL, String reqURL)
585:                    throws WebServiceException, IOException {
586:                // TODO Auto-generated method stub
587:                return srpWSDLProcessor.getWSDL(serviceInfo.name, serverURL,
588:                        reqURL);
589:            }
590:
591:            public void serialize(Element rootConfig, String indent,
592:                    String delta, Writer w) throws IOException {
593:                Element serviceElem = XMLUtil.getSubElement(rootConfig,
594:                        "deployment");
595:                if (serviceElem != null) {
596:                    DOM2Writer.serializeAsXML(serviceElem, w, true, true,
597:                            "UTF-8", indent.length(), delta.length());
598:                }
599:            }
600:
601:            protected void intercept(RequestInfo reqInfo, InterceptorChain chain)
602:                    throws WebServiceException, IOException {
603:                // HttpServletResponse res = Current.getRequestContext().getHttpServletResponse();
604:                SOAPEnvelope resEnv = null;
605:                MessageContext msgContext = AxisEngine
606:                        .getCurrentMessageContext();
607:                Message reqMsg = msgContext.getRequestMessage();
608:                Message responseMsg = null;
609:                SOAPService service = msgContext.getService();
610:                OperationDesc operation = msgContext.getOperation();
611:                if (operation != null
612:                        && operation.getMep() == OperationType.ONE_WAY) {
613:                    msgContext.setResponseMessage(null);
614:                } else {
615:                    responseMsg = msgContext.getResponseMessage();
616:
617:                    // If we didn't have a response message, make sure we set one up
618:                    // with the appropriate versions of SOAP and Schema
619:                    if (responseMsg == null) {
620:                        resEnv = new SOAPEnvelope(
621:                                msgContext.getSOAPConstants(), msgContext
622:                                        .getSchemaVersion());
623:
624:                        responseMsg = new Message(resEnv);
625:                        String encoding = XMLUtils.getEncoding(msgContext);
626:                        try {
627:                            responseMsg.setProperty(
628:                                    SOAPMessage.CHARACTER_SET_ENCODING,
629:                                    encoding);
630:                        } catch (SOAPException se) {
631:                            throw new WebServiceException(
632:                                    "Failed to set message encoding", se);
633:                        }
634:                        msgContext.setResponseMessage(responseMsg);
635:                    } else {
636:                        resEnv = responseMsg.getSOAPEnvelope();
637:                    }
638:                }
639:
640:                try {
641:                    SOAPEnvelope reqEnv = reqMsg.getSOAPEnvelope();
642:                    // service.invoke(msgContext);
643:                    if (service.getStyle().equals(Style.MESSAGE)) {
644:                        srpMsgProvider.processMessage(msgContext, reqEnv,
645:                                resEnv, reqInfo, chain);
646:                    } else {
647:                        srpRPCProvider.processMessage(msgContext, reqEnv,
648:                                resEnv, reqInfo, chain);
649:                    }
650:                    if (reqInfo.redirect != null)
651:                        return;
652:                    msgContext.setPastPivot(true);
653:
654:                } catch (UnavailableException ex) {
655:                    reqInfo.serviceInfo.loadError = ex;
656:                    reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
657:                    reqInfo.serviceInfo.webService = null;
658:                    msgContext.setPastPivot(true);
659:                    AxisFault fault = AxisFault.makeFault(ex);
660:                    srpAxisServlet.processAxisFault(fault);
661:                    // srpAxisServlet.configureResponseFromAxisFault(res, fault);
662:                    responseMsg = new Message(fault);
663:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
664:                            .getMessage().setMessageContext(msgContext);
665:                    throw ex;
666:                } catch (WebServiceSecurityException ex) {
667:                    msgContext.setPastPivot(true);
668:                    AxisFault fault = AxisFault.makeFault(ex);
669:                    srpAxisServlet.processAxisFault(fault);
670:                    // res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
671:                    responseMsg = new Message(fault);
672:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
673:                            .getMessage().setMessageContext(msgContext);
674:                    throw ex;
675:                } catch (WebServiceException ex) {
676:                    Throwable cause = ex;
677:                    if (ex.getCause() != null)
678:                        cause = ex.getCause();
679:                    msgContext.setPastPivot(true);
680:                    if (cause instanceof  Exception) {
681:                        AxisFault fault = AxisFault
682:                                .makeFault((Exception) cause);
683:                        srpAxisServlet.processAxisFault(fault);
684:                        // srpAxisServlet.configureResponseFromAxisFault(res, fault);
685:                        responseMsg = new Message(fault);
686:                    } else {
687:                        reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
688:                        reqInfo.serviceInfo.loadError = cause;
689:                        // other exceptions are internal trouble
690:                        responseMsg = msgContext.getResponseMessage();
691:                        // res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
692:                        responseMsg = srpAxisServlet
693:                                .convertExceptionToAxisFault(cause, responseMsg);
694:
695:                    }
696:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
697:                            .getMessage().setMessageContext(msgContext);
698:                    throw ex;
699:
700:                } catch (AxisFault fault) {
701:                    // log and sanitize
702:                    msgContext.setPastPivot(true);
703:                    srpAxisServlet.processAxisFault(fault);
704:                    // srpAxisServlet.configureResponseFromAxisFault(res, fault);
705:                    // responseMsg = msgContext.getResponseMessage();
706:                    // if (responseMsg == null) {
707:                    responseMsg = new Message(fault);
708:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
709:                            .getMessage().setMessageContext(msgContext);
710:                    // }
711:                    throw new WebServiceException("Axis processing failed.",
712:                            fault);
713:                } catch (Exception ex) {
714:                    msgContext.setPastPivot(true);
715:                    reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
716:                    reqInfo.serviceInfo.loadError = ex;
717:                    reqInfo.serviceInfo.webService = null;
718:                    AxisFault fault = AxisFault.makeFault(ex);
719:                    srpAxisServlet.processAxisFault(fault);
720:                    //srpAxisServlet.configureResponseFromAxisFault(res, fault);
721:                    // responseMsg = msgContext.getResponseMessage();
722:                    // if (responseMsg == null) {
723:                    responseMsg = new Message(fault);
724:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
725:                            .getMessage().setMessageContext(msgContext);
726:                    // }
727:                    throw fault;
728:                } catch (Throwable t) {
729:                    msgContext.setPastPivot(true);
730:                    reqInfo.serviceInfo.status = WebServiceServerConstants.LOAD_STATUS_METHOD_INVOCATION_ERROR;
731:                    reqInfo.serviceInfo.loadError = t;
732:                    // other exceptions are internal trouble
733:                    responseMsg = msgContext.getResponseMessage();
734:                    //res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
735:                    responseMsg = srpAxisServlet.convertExceptionToAxisFault(t,
736:                            responseMsg);
737:                    ((org.apache.axis.SOAPPart) responseMsg.getSOAPPart())
738:                            .getMessage().setMessageContext(msgContext);
739:                    throw new UnavailableException(
740:                            "Error in processing web service request.", t);
741:                } finally {
742:                    msgContext.setResponseMessage(responseMsg);
743:                }
744:
745:            }
746:
747:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.