2 * Copyright 2016 [ZTE] and others.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.openo.commontosca.catalog.model.plan.wso2;
\r
18 import java.util.Map;
\r
20 import org.glassfish.jersey.client.ClientConfig;
\r
21 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
\r
22 import org.openo.commontosca.catalog.model.plan.wso2.entity.DeletePackageResponse;
\r
23 import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessResponse;
\r
24 import org.openo.commontosca.catalog.model.plan.wso2.entity.DeployPackageResponse;
\r
25 import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessRequest;
\r
27 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
\r
34 public class WSO2ServiceConsumer {
\r
35 public static final String WSO2_BASE_URL = "http://localhost:9449/";
\r
41 * @throws CatalogResourceException
\r
43 public static DeployPackageResponse deployPackage(String filePath)
\r
44 throws CatalogResourceException {
\r
46 // final FormDataMultiPart formData = new FormDataMultiPart();
\r
47 // final BodyPart bodyPart = new FormDataBodyPart(fileDetail,
\r
48 // uploadedInputStream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
\r
49 // formData.bodyPart(bodyPart);
\r
50 // formData.setContentDisposition(fileDetail);
\r
51 // formData.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
\r
52 // final Client client = ClientBuilder.newBuilder()
\r
53 // .register(MultiPartFeature.class).build();
\r
54 // final WebTarget target = client.target(getPackageURL()).path(
\r
55 // "/containerapi/CSARs");
\r
56 // final Response response = target.request().post(
\r
57 // Entity.entity(formData, formData.getMediaType()));
\r
62 // ClientConfig config = new ClientConfig();
\r
63 // IWSO2RestService yamlParseProxy = ConsumerFactory
\r
64 // .createConsumer(MSBUtil.getYamlParseBaseUrl(), config,
\r
65 // IWSO2RestService.class);
\r
66 // String jsonStr = yamlParseProxy.parse(request);
\r
67 // return new Gson().fromJson(jsonStr, ParseYamlResult.class);
\r
68 // } catch (Exception e) {
\r
69 // throw new CatalogResourceException("Call parser api failed.", e);
\r
76 * @param packageName
\r
78 * @throws CatalogResourceException
\r
80 DeletePackageResponse deletePackage(String packageName)
\r
81 throws CatalogResourceException {
\r
83 ClientConfig config = new ClientConfig();
\r
84 IWSO2RestService wso2Proxy = ConsumerFactory.createConsumer(
\r
85 WSO2_BASE_URL, config, IWSO2RestService.class);
\r
86 DeletePackageResponse response = wso2Proxy
\r
87 .deletePackage(packageName);
\r
88 if (response.isSuccess()) {
\r
91 throw new CatalogResourceException(response.getException());
\r
92 } catch (Exception e) {
\r
93 throw new CatalogResourceException(
\r
94 "Call Delete Package api failed.", e);
\r
103 * @throws CatalogResourceException
\r
105 StartProcessResponse startProcess(String processId,
\r
106 Map<String, Object> params) throws CatalogResourceException {
\r
108 ClientConfig config = new ClientConfig();
\r
109 IWSO2RestService wso2Proxy = ConsumerFactory.createConsumer(
\r
110 WSO2_BASE_URL, config, IWSO2RestService.class);
\r
111 StartProcessResponse response = wso2Proxy
\r
112 .startProcess(new StartProcessRequest(processId, params));
\r
113 if (response.isSuccess()) {
\r
116 throw new CatalogResourceException(response.getException());
\r
117 } catch (Exception e) {
\r
118 throw new CatalogResourceException(
\r
119 "Call Start Process api failed.", e);
\r