This project has retired. For details please refer to its
Attic page.
ValidateValuesFromWebService xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.validation;
17
18 import java.util.List;
19 import javax.xml.ws.BindingProvider;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.juddi.api.impl.UDDIValueSetValidationImpl;
23 import org.apache.juddi.config.Property;
24 import org.apache.juddi.v3.client.UDDIConstants;
25 import org.apache.juddi.v3.client.UDDIService;
26 import org.apache.juddi.v3.error.ErrorMessage;
27 import org.apache.juddi.v3.error.ValueNotAllowedException;
28 import org.uddi.api_v3.BindingTemplate;
29 import org.uddi.api_v3.BusinessEntity;
30 import org.uddi.api_v3.BusinessService;
31 import org.uddi.api_v3.PublisherAssertion;
32 import org.uddi.api_v3.TModel;
33 import org.uddi.v3_service.UDDIValueSetValidationPortType;
34 import org.uddi.vs_v3.ValidateValues;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class ValidateValuesFromWebService {
52
53 private static final Log log = LogFactory.getLog(ValidateValuesFromWebService.class);
54
55 private static UDDIValueSetValidationPortType getPort(String url) throws ValueNotAllowedException {
56 UDDIService svc = new UDDIService();
57 UDDIValueSetValidationPortType vsv = svc.getUDDIValueSetValidationPort();
58
59 if (url == null || url.trim().length() == 0) {
60 log.error("VSV Validation Failed: Calling Url is null");
61 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidurl"));
62 throw x;
63 } else if (url.startsWith(Property.DEFAULT_BASE_URL)
64 || url.startsWith(Property.DEFAULT_BASE_URL_SECURE)) {
65 vsv = new UDDIValueSetValidationImpl();
66
67 } else if (url.startsWith("classpath:/")) {
68 try {
69 String clz = url.substring(11);
70 Class<UDDIValueSetValidationPortType> forName = (Class<UDDIValueSetValidationPortType>) Class.forName(clz);
71 vsv = forName.newInstance();
72 } catch (Exception ex) {
73 log.error("VSV Validation Failed: Cannot locate class from url " + url, ex);
74 }
75 } else if (url.toLowerCase().startsWith("http")){
76
77 log.info("Calling External VSV Service");
78 ((BindingProvider) vsv).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
79 }
80 else
81 {
82 log.warn("Unable to figure out how to use the URL " + url + " as a Value Set Validation Service transport mechanism.");
83 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidurl", url));
84 throw x;
85 }
86
87 return vsv;
88 }
89
90
91
92 public static void ValidateTModel(String url, List<TModel> obj) throws ValueNotAllowedException {
93 UDDIValueSetValidationPortType vsv = getPort(url);
94 ValidateValues req = new ValidateValues();
95 req.getTModel().addAll(obj);
96
97 try {
98 vsv.validateValues(req);
99 } catch (Exception ex) {
100 log.warn(ex.getMessage());
101 log.debug(ex.getMessage(),ex);
102 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
103 throw x;
104 }
105 }
106
107 public static void ValidateBinding(String url, List<BindingTemplate> obj) throws ValueNotAllowedException {
108 UDDIValueSetValidationPortType vsv = getPort(url);
109 ValidateValues req = new ValidateValues();
110 req.getBindingTemplate().addAll(obj);
111
112 try {
113 vsv.validateValues(req);
114 } catch (Exception ex) {
115 log.warn(ex.getMessage());
116 log.debug(ex.getMessage(),ex);
117 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
118 throw x;
119 }
120 }
121
122 public static void ValidateService(String url, List<BusinessService> obj) throws ValueNotAllowedException {
123 UDDIValueSetValidationPortType vsv = getPort(url);
124 ValidateValues req = new ValidateValues();
125 req.getBusinessService().addAll(obj);
126
127 try {
128 vsv.validateValues(req);
129 } catch (Exception ex) {
130 log.warn(ex.getMessage());
131 log.debug(ex.getMessage(),ex);
132 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
133 throw x;
134 }
135 }
136
137
138 public static void ValidateBusiness(String url, List<BusinessEntity> obj) throws ValueNotAllowedException {
139 UDDIValueSetValidationPortType vsv = getPort(url);
140 ValidateValues req = new ValidateValues();
141 req.getBusinessEntity().addAll(obj);
142
143 try {
144 vsv.validateValues(req);
145 } catch (Exception ex) {
146 log.warn(ex.getMessage());
147 log.debug(ex.getMessage(),ex);
148 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
149 throw x;
150 }
151 }
152
153 public static void ValidatePubAss(String url, PublisherAssertion obj) throws ValueNotAllowedException {
154 UDDIValueSetValidationPortType vsv = getPort(url);
155 ValidateValues req = new ValidateValues();
156 req.getPublisherAssertion().add(obj);
157 try {
158 vsv.validateValues(req);
159 } catch (Exception ex) {
160 log.warn(ex.getMessage());
161 log.debug(ex.getMessage(),ex);
162 ValueNotAllowedException x = new ValueNotAllowedException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", ex.getMessage()));
163 throw x;
164 }
165 }
166 }