View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.v3.client.transport.wrapper;
17  
18  import java.rmi.RemoteException;
19  import java.util.Map;
20  import javax.xml.ws.Binding;
21  import javax.xml.ws.BindingProvider;
22  import javax.xml.ws.EndpointReference;
23  import javax.xml.ws.soap.SOAPFaultException;
24  import org.apache.juddi.v3.client.UDDIServiceV2;
25  import org.apache.juddi.v3.client.mapping.MapUDDIv2Tov3;
26  import org.apache.juddi.v3.client.mapping.MapUDDIv3Tov2;
27  import org.uddi.api_v3.AuthToken;
28  import org.uddi.api_v3.DiscardAuthToken;
29  import org.uddi.api_v3.GetAuthToken;
30  import org.uddi.v2_service.DispositionReport;
31  import org.uddi.v2_service.Publish;
32  import org.uddi.v3_service.DispositionReportFaultMessage;
33  import org.uddi.v3_service.UDDISecurityPortType;
34  
35  /**
36   * This class provides a wrapper to enable UDDIv3 clients to talk to UDDIv2
37   * servers via JAXWS Transport. It handles all translations for Security 
38   * service methods.
39   *
40   * @author <a href="alexoree@apache.org">Alex O'Ree</a>
41   * @since 3.2
42   */
43  public class Security3to2 implements UDDISecurityPortType, BindingProvider {
44  
45          Publish publishService = null;
46  
47          public Security3to2() {
48  
49                  UDDIServiceV2 service = new UDDIServiceV2();
50                  publishService = service.getPublish();
51  
52          }
53  
54          @Override
55          public void discardAuthToken(DiscardAuthToken body) throws DispositionReportFaultMessage, RemoteException {
56                  try {
57                          org.uddi.api_v2.DiscardAuthToken discardAuthToken = new org.uddi.api_v2.DiscardAuthToken();
58                          discardAuthToken.setAuthInfo(body.getAuthInfo());
59                          discardAuthToken.setGeneric(MapUDDIv3Tov2.VERSION);
60                          publishService.discardAuthToken(discardAuthToken);
61                  } catch (DispositionReport ex) {
62                          throw MapUDDIv2Tov3.MapException(ex);
63                  } catch (SOAPFaultException ex) {
64                          throw MapUDDIv2Tov3.MapException(ex);
65                  }
66          }
67  
68          @Override
69          public AuthToken getAuthToken(GetAuthToken body) throws DispositionReportFaultMessage, RemoteException {
70                  org.uddi.api_v2.GetAuthToken authToken = new org.uddi.api_v2.GetAuthToken();
71                  authToken.setGeneric(MapUDDIv3Tov2.VERSION);
72                  authToken.setCred(body.getCred());
73                  authToken.setUserID(body.getUserID());
74                  try {
75                          org.uddi.api_v2.AuthToken authToken1 = publishService.getAuthToken(authToken);
76                          AuthToken r = new AuthToken();
77                          r.setAuthInfo(authToken1.getAuthInfo());
78                          return r;
79                  } catch (DispositionReport ex) {
80                          throw MapUDDIv2Tov3.MapException(ex);
81                  }  catch (SOAPFaultException ex) {
82                          throw MapUDDIv2Tov3.MapException(ex);
83                  }
84          }
85  
86          
87          @Override
88          public Map<String, Object> getRequestContext() {
89                  return ((BindingProvider)publishService).getRequestContext();
90          }
91  
92          @Override
93          public Map<String, Object> getResponseContext() {
94                  return ((BindingProvider)publishService).getResponseContext();
95          }
96  
97          @Override
98          public Binding getBinding() {
99                  return ((BindingProvider)publishService).getBinding();
100         }
101 
102         @Override
103         public EndpointReference getEndpointReference() {
104                 return ((BindingProvider)publishService).getEndpointReference();
105         }
106 
107         @Override
108         public <T extends EndpointReference> T getEndpointReference(Class<T> clazz) {
109                 return ((BindingProvider)publishService).getEndpointReference(clazz);
110         }
111 }