01: /**
02: * $Id: PortTypeInit.java,v 1.5 2005/12/14 07:02:55 rt130506 Exp $
03: * Copyright 2003 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.wsrp.producer;
14:
15: import javax.servlet.ServletRequest;
16: import javax.servlet.http.HttpServletRequest;
17: import javax.servlet.ServletContext;
18:
19: import com.sun.portal.wsrp.producer.Producer;
20: import com.sun.portal.wsrp.producer.ProducerManager;
21: import com.sun.portal.wsrp.producer.ProducerException;
22: import com.sun.portal.wsrp.producer.InvalidRegistrationException;
23: import com.sun.portal.wsrp.producer.ISConnection;
24:
25: import com.sun.portal.wsrp.producer.router.RouterServlet;
26:
27: import com.sun.portal.wsrp.producer.filter.ProducerThreadLocalizer;
28:
29: import com.sun.portal.wsrp.common.stubs.RegistrationContext;
30:
31: import com.iplanet.sso.SSOToken;
32:
33: public class PortTypeInit {
34: public static Producer getProducer() throws ProducerException {
35: return getProducer(null);
36: }
37:
38: public static Producer getProducer(RegistrationContext rctx)
39: throws ProducerException {
40: ServletRequest sreq = ProducerThreadLocalizer.getRequest();
41: if (sreq == null) {
42: throw new ProducerException(
43: "could not get servlet request from thread local space");
44: }
45:
46: ServletContext ctx = ProducerThreadLocalizer.getContext();
47: if (ctx == null) {
48: throw new ProducerException(
49: "could not get servlet context from thread local space");
50: }
51:
52: HttpServletRequest req = (HttpServletRequest) sreq;
53: SSOToken adminToken = ISConnection.getAdminToken();
54: String producerKey = (String) req
55: .getAttribute(RouterServlet.WSRP_PRODUCER_KEY);
56:
57: ProducerManager producerManager = new com.sun.portal.wsrp.producer.impl.ProducerManagerImpl(
58: req, ctx, adminToken);
59: Producer producer = producerManager.getProducer(producerKey);
60:
61: if (producerManager.areAllProducersDisabled()) {
62: throw new ProducerException("all producers disabled");
63: }
64: if (!producer.isEnabled()) {
65: throw new ProducerException("was not enabled, producerKey="
66: + producer.getProducerKey());
67: }
68:
69: if (rctx != null) {
70: String handle = rctx.getRegistrationHandle();
71: if (handle != null) {
72: boolean status = false;
73: try {
74: status = producer.getRegistrationManager()
75: .getRegistrationStatus(handle);
76: } catch (ProducerException pe) {
77: // The registration has been manually deleted by admin
78: // So ou does not exists, Hence this exception. Send invalid registration fault
79: throw new InvalidRegistrationException(
80: "registration was deleted, producerKey="
81: + producer.getProducerKey()
82: + ", handle=" + handle, pe);
83: }
84: if (!status) {
85: throw new ProducerException(
86: "registration was disabled, producerKey="
87: + producer.getProducerKey()
88: + ", handle=" + handle);
89: }
90: }
91: }
92:
93: return producer;
94: }
95: }
|