1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.jbi.endpoint;
9
10 import it.imolinfo.jbi4ejb.Logger;
11 import it.imolinfo.jbi4ejb.LoggerFactory;
12 import it.imolinfo.jbi4ejb.descriptor.ProviderServiceDescriptor;
13 import it.imolinfo.jbi4ejb.exception.Jbi4EjbException;
14 import it.imolinfo.jbi4ejb.jbi.Messages;
15 import it.imolinfo.jbi4ejb.jbi.component.runtime.AbstractComponentLifeCycle;
16 import it.imolinfo.jbi4ejb.jbi.component.runtime.RuntimeHelper;
17 import it.imolinfo.jbi4ejb.processor.ProviderExchangeProcessor;
18 import it.imolinfo.jbi4ejb.runtime.ProviderServiceCreator;
19 import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxy;
20 import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxyFactory;
21 import it.imolinfo.jbi4ejb.webservice.generator.Util;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.File;
25 import java.util.List;
26
27 import javax.xml.namespace.QName;
28
29 import org.codehaus.xfire.XFire;
30 import org.codehaus.xfire.service.Service;
31
32
33
34
35
36
37 public class Jbi4EjbProviderEndpoint extends Jbi4EjbEndpoint {
38
39 private static final long serialVersionUID = -7829120677780408268L;
40
41
42 private static final Logger LOG
43 = LoggerFactory.getLogger(Jbi4EjbProviderEndpoint.class);
44 final Messages MESSAGES = Messages.getMessages(Jbi4EjbProviderEndpoint.class);
45
46
47 private ProviderServiceDescriptor serviceDescriptor;
48
49
50 private Service xfireService;
51
52
53
54
55
56
57
58
59
60
61 public Jbi4EjbProviderEndpoint(QName serviceName, String endpointName) throws Jbi4EjbException {
62 super(serviceName, endpointName);
63 this.setExchangeProcessor(new ProviderExchangeProcessor(this));
64 }
65
66
67
68
69
70
71
72
73
74
75 public void registerService() throws Jbi4EjbException {
76 LOG.debug("Registering xfire service for: " + this.getServiceName());
77
78 XFire xfire = this.getSuManager().getLifeCycle().getXfire();
79
80 File wsdl = this.getEndpointWSDL();
81
82
83 String deployDirectoryName = serviceDescriptor.getComponentRootPath() + "/" + serviceDescriptor.hashCode();
84 LOG.debug("Starting deploy using root path: " + deployDirectoryName);
85 File rootDir = new File(deployDirectoryName);
86 if (!rootDir.exists()) {
87 boolean result = rootDir.mkdir();
88 if (!result) {
89 String msg=MESSAGES.getString("EJB000301_Error_creating_working_directory", new Object[] {rootDir.getAbsolutePath()});
90 LOG.error(msg);
91 throw new Jbi4EjbException(msg);
92
93 } else {
94 LOG.debug("created working directory: " + rootDir.getAbsolutePath());
95 }
96 }
97
98
99 List<String> jarFilesName = Util.prepareClassPath(RuntimeHelper.getComponentContext().getInstallRoot());
100
101
102 StatelessEJBProxy ejbProxy = StatelessEJBProxyFactory.createEJBProxy(wsdl, serviceDescriptor, rootDir, jarFilesName);
103
104
105 serviceDescriptor.setEjbProxy(ejbProxy);
106
107
108 ProviderServiceCreator serviceCreator = new ProviderServiceCreator();
109
110
111 xfireService = serviceCreator.createJbiService(this.serviceDescriptor,
112 xfire);
113 xfire.getServiceRegistry().register(xfireService);
114
115
116 ByteArrayOutputStream baos = new ByteArrayOutputStream();
117 LOG.debug("xfireService:" + xfireService);
118 xfire.generateWSDL(xfireService.getSimpleName(), baos);
119 if (LOG.isDebugEnabled()) {
120 LOG.debug("WSDL:\n------------------\n"
121 + baos.toString()
122 + "\n------------------");
123 }
124
125 }
126
127
128
129
130
131
132
133 public void unregisterService() throws Jbi4EjbException {
134
135 LOG.info("EJB000302_unregister_Service", new Object[]{this.getServiceName()}, new Object[]{this.getEndpointName()});
136 }
137
138
139
140
141
142
143 public void validate() throws Jbi4EjbException {
144
145 }
146
147
148
149
150
151
152 public ProviderServiceDescriptor getServiceDescriptor() {
153 return serviceDescriptor;
154 }
155
156
157
158
159
160
161
162 public void setServiceDescriptor(ProviderServiceDescriptor serviceDescriptor) {
163 this.serviceDescriptor = serviceDescriptor;
164 }
165
166
167
168
169
170
171 public Service getXfireService() {
172 return xfireService;
173 }
174
175 }