1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package com.att.nsa.mr.client.impl;
24 import javax.ws.rs.client.Client;
25 import javax.ws.rs.client.ClientBuilder;
26 import javax.ws.rs.client.Entity;
27 import javax.ws.rs.client.WebTarget;
28 import javax.ws.rs.core.Response;
30 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
32 public class DmaapClientUtil {
34 private static final String MR_AUTH_CONSTANT = "X-CambriaAuth";
35 private static final String MR_DATE_CONSTANT = "X-CambriaDate";
37 public static WebTarget getTarget(final String path, final String username, final String password) {
39 Client client = ClientBuilder.newClient();
40 HttpAuthenticationFeature feature = HttpAuthenticationFeature.universal(username, password);
41 client.register(feature);
43 return client.target(path);
46 public static WebTarget getTarget(final String path) {
48 Client client = ClientBuilder.newClient();
49 return client.target(path);
52 public static Response getResponsewtCambriaAuth(WebTarget target, String username, String password) {
53 return target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).get();
57 public static Response postResponsewtCambriaAuth(WebTarget target, String username, String password,byte[] data, String contentType) {
58 return target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).post(Entity.entity(data, contentType));
62 public static Response getResponsewtBasicAuth(WebTarget target, String authHeader) {
64 return target.request().header("Authorization", "Basic " + authHeader).get();
68 public static Response postResponsewtBasicAuth(WebTarget target, String authHeader,byte[] data,String contentType) {
70 return target.request().header("Authorization", "Basic " + authHeader).post(Entity.entity(data, contentType));
74 public static Response getResponsewtNoAuth(WebTarget target) {
76 return target.request().get();
80 public static Response postResponsewtNoAuth(WebTarget target, byte[] data, String contentType) {
81 return target.request().post(Entity.entity(data, contentType));