<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ Copyright 2016 Huawei Technologies Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<artifactId>commonlib-cbb</artifactId>
<packaging>jar</packaging>
<properties>
+ <cxf.version>3.1.6</cxf.version>
</properties>
<dependencies>
<dependency>
<version>1.0-1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-hc</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-jaxrs</artifactId>
+ <version>1.9.2</version>
+ </dependency>
</dependencies>
<build>
<plugins>
--- /dev/null
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.baseservice.bus.util;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
+import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Provide the service register cbb for common use.
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+public class RegisterService {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegisterService.class);
+
+ private static final String BUS_CONFIGURE_FILE = "/etc/microservice.ini";
+
+ private static final String BUS_SERVICE_URL = "/openoapi/microservices/v1/services";
+
+ private static final String BUS_ADDRESS_KEY = "msb.address";
+
+ private static String busPath = null;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ * @throws IOException
+ *
+ * @since
+ */
+ private RegisterService() {
+ }
+
+ /**
+ * register the micro service.
+ * <br/>
+ *
+ * @param jsonPath: the service json object to register to the bus.
+ * @param createOrUpdate: true, create and update the old ip port. false, create and delete the
+ * old one;
+ * @return
+ * @throws IOException
+ * @since
+ */
+ public static Response registerService(String jsonPath, boolean createOrUpdate) throws IOException {
+
+ String serviceInfo = getServiceModel(jsonPath);
+
+ WebClient client = initializeClient();
+
+ client.type("application/json");
+
+ client.accept("application/json");
+
+ client.path(BUS_SERVICE_URL);
+
+ client.query("createOrUpdate", createOrUpdate);
+
+ LOGGER.info("Connecting bus address : " + busPath + BUS_SERVICE_URL);
+
+ return client.invoke("POST", serviceInfo);
+
+ }
+
+ /**
+ * get the service's model. and return it as a string ;
+ * <br/>
+ *
+ * @param jsonPath
+ * @return
+ * @since
+ */
+ private static String getServiceModel(String jsonPath) {
+
+ String serviceInfo = "";
+
+ try {
+ LOGGER.info("begin to read file micro service json " + jsonPath);
+
+ FileInputStream busFile = new FileInputStream(jsonPath);
+
+ int size = busFile.available();
+
+ byte[] buffer = new byte[size];
+
+ busFile.read(buffer);
+
+ busFile.close();
+
+ serviceInfo = new String(buffer);
+ LOGGER.info("finished to read micro service json file. ");
+ } catch(Exception ex) {
+ LOGGER.error("Read the micro service json file error :", ex);
+ }
+ return serviceInfo;
+ }
+ /**
+ * initialize the bus ip and port.
+ * <br/>
+ *
+ * @return
+ * @throws IOException
+ * @since
+ */
+ private static String getBusAdderss() throws IOException {
+
+ LOGGER.info("begin to get the bus baseurl.");
+ FileInputStream busFile = null;
+ String url = "msb.openo.org:80";
+
+ String filePath = SystemEnvVariablesFactory.getInstance().getAppRoot() + BUS_CONFIGURE_FILE;
+ LOGGER.info("bus base url file:" + filePath);
+
+ Properties properties = new Properties();
+
+ try {
+ busFile = new FileInputStream(filePath);
+ properties.load(busFile);
+ url = properties.getProperty(BUS_ADDRESS_KEY);
+ } catch(IOException e) {
+ if (busFile != null) {
+ busFile.close();
+ }
+ LOGGER.error("Read the bus url failed: ", e);
+ }
+
+ LOGGER.info("initialize the bus baseurl is: " + url);
+ return "http://" + url;
+ }
+
+ /**
+ * get the bus's client's address. and initialize the web client.
+ * <br/>
+ *
+ * @return
+ * @throws IOException
+ * @since
+ */
+ private static WebClient initializeClient() throws IOException {
+
+ final List<Object> providers = new ArrayList<Object>();
+
+ JacksonJsonProvider jacksonJsonProvider = new JacksonJsonProvider();
+
+ providers.add(jacksonJsonProvider);
+
+ if (busPath == null) {
+ busPath = getBusAdderss();
+ }
+
+ return WebClient.create(busPath, providers);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.baseservice.bus.util;
+
+import java.io.File;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.openo.baseservice.util.impl.SystemEnvVariablesFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Initialize the service register listener.
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+public class RegisterServiceListener implements ServletContextListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RegisterServiceListener.class);
+
+ private static final String JSON = "json";
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+
+ String servicePath = SystemEnvVariablesFactory.getInstance().getAppRoot() + "/etc/microservice";
+ LOGGER.info("microservices json file path is" + servicePath);
+
+ File file = new File(servicePath);
+
+ File[] fileList = file.listFiles();
+
+ for(File tempFile : fileList) {
+ String fileName = tempFile.getName();
+ if (fileName.substring(fileName.lastIndexOf(".") + 1).equalsIgnoreCase(JSON)) {
+ LOGGER.info("begin to initialize the service file" + tempFile.getAbsolutePath());
+
+ /** now because ZTE do not provide the service bus.commont this code first.
+ try {
+ RegisterService.registerService(tempFile.getAbsolutePath(), true);
+ } catch(IOException e) {
+ LOGGER.error("Faile to register the service file :" + tempFile.getPath() + ", exception:" + e);
+ }
+ */
+ }
+ }
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 08-Jun-2016
+ * @version 08-Jun-2016
*/
public final class CipherCreator {
* private
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
private CipherCreator() {
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public static CipherCreator instance() {
return instance;
* <br/>
*
* @return cipher instance with default key.
- * @since SDNO 0.5
+ * @since
*/
public AbstractCipher create() {
return factory.createCipherManager();
*
* @param key the key to be used for encryption and decryption.
* @return cipher instance with specified key.
- * @since SDNO 0.5
+ * @since
*/
public AbstractCipher create(final String key) {
return factory.createCipherManager(key);
* <br/>
*
* @param factory cipher factory.
- * @since SDNO 0.5
+ * @since
*/
public void setFactory(final AbstractCipherFactory factory) {
this.factory = factory;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 31-May-2016
+ * @version 31-May-2016
*/
public class AesCipher implements AbstractCipher {
* Creates default key.
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
public AesCipher() {
super();
}
/**
+ *
* Constructor<br/>
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param ckey: key.
*/
public AesCipher(final String key) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 03-Jun-2016
+ * @version 03-Jun-2016
*/
public class AesCipherFactory implements AbstractCipherFactory {
* Creates new CipherManager instance.<br/>
*
* @return new cipher manager instance.
- * @since SDNO 0.5
+ * @since
*/
@Override
public AbstractCipher createCipherManager() {
*
* @param key new cipher manager instance.
* @return
- * @since SDNO 0.5
+ * @since
*/
@Override
public AbstractCipher createCipherManager(final String key) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 31-May-2016
+ * @version 31-May-2016
*/
public interface AbstractCipher {
*
* @param plain string to be encrypted.
* @return encrypted string.
- * @since SDNO 0.5
+ * @since
*/
String encrypt(String plain);
*
* @param encrypted String is encrypted by AES 128
* @return plain after decrypt
- * @since SDNO 0.5
+ * @since
*/
String decrypt(String encrypted);
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 03-Jun-2016
+ * @version 03-Jun-2016
*/
public interface AbstractCipherFactory {
* Creates new CipherManager instance.<br/>
*
* @return new cipher manager instance.
- * @since SDNO 0.5
+ * @since
*/
AbstractCipher createCipherManager();
*
* @param key new cipher manager instance.
* @return
- * @since SDNO 0.5
+ * @since
*/
AbstractCipher createCipherManager(final String key);
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 03-Jun-2016
+ * @version 03-Jun-2016
*/
public final class Sha256 {
*
* @param data: The data to be digested.
* @return Hex encoded digested data.
- * @since SDNO 0.5
+ * @since
*/
public static String digest(final String data) {
final byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
* @param key: The signing key.
* @return Hex encoded HMAC signature.
* @throws InvalidKeyException if the key is invalid.
- * @since SDNO 0.5
+ * @since
*/
public static String mac(final String data, final Key key) throws InvalidKeyException {
final byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
* @param data: The data to be signed.
* @param secret: The signing key.
* @return Hex encoded HMAC signature.
- * @since SDNO 0.5
+ * @since
*/
public static String mac(final String data, final byte[] secret) {
final Key key = new SecretKeySpec(secret, "HmacSHA256");
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 31-May-2016
+ * @version 31-May-2016
*/
public final class RestUtils {
*
* @param request : request object.
* @return Request body as string.
- * @since SDNO 0.5
+ * @since
*/
public static String getRequestBody(final HttpServletRequest request) {
String body = null;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 24-Jun-2016
+ * @version 24-Jun-2016
*/
-public class SystemEnvVariablesDefImpl extends SystemEnvVariables {
+public class SystemEnvVariablesDefImpl implements SystemEnvVariables {
private static final Logger LOG = LoggerFactory.getLogger(SystemEnvVariablesDefImpl.class);
*
* @param inPath input path
* @return the canonical path.
- * @since SDNO 0.5
+ * @since
*/
private String getCanonicalPath(final String inPath) {
String path = null;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 2016年8月13日
+ * @version
*/
public class SystemEnvVariablesFactory {
private static SystemEnvVariables systemEnvVariablesInstance = new SystemEnvVariablesDefImpl();
+ /**
+ *
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since
+ */
+ private SystemEnvVariablesFactory() {
+
+ }
/**
* get the SystemEnvVariables instance
* <br/>
*
* @return SystemEnvVariables instance
- * @since SDNO 0.5
+ * @since
*/
public static SystemEnvVariables getInstance() {
return systemEnvVariablesInstance;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 31-May-2016
+ * @version 31-May-2016
*/
-public abstract class SystemEnvVariables {
+public interface SystemEnvVariables {
/**
* Get application root path <br/>
*
* @return application root path.
- * @since SDNO 0.5
+ * @since
*/
- public abstract String getAppRoot();
+ String getAppRoot();
}
--- /dev/null
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.baseservice.bus.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.util.impl.SystemEnvVariablesDefImpl;
+
+import junit.framework.Assert;
+import mockit.Mock;
+import mockit.MockUp;
+
+public class TestRegisterService {
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+
+ }
+
+ @Test
+ public void testregisterServce() throws IOException {
+
+ File file = new File("");
+ Response res = null;
+
+ final String path = file.getAbsolutePath();
+
+ new MockUp<SystemEnvVariablesDefImpl>() {
+ @Mock
+ public String getAppRoot() {
+ return path;
+ }
+ };
+
+ try {
+ res = RegisterService.registerService(path, true);
+ } catch(Exception e) {
+ Assert.assertNotNull(e);
+ }
+
+ }
+}
+
--- /dev/null
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.baseservice.bus.util;
+
+import java.io.File;
+
+import javax.servlet.ServletContextEvent;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class TestRegisterServiceListener {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+
+ }
+
+ @Test
+ public void testRegisterServiceListener() {
+
+ RegisterServiceListener impl = new RegisterServiceListener();
+
+ ServletContextEvent sce = null;
+
+ new MockUp<File>() {
+ @Mock
+ public File[] listFiles() {
+ File file = new File("");
+ File[] filelist = new File[]{file};
+ return filelist;
+ }
+
+ };
+
+ impl.contextInitialized(sce);
+ }
+
+}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 02-Jun-2016
+ * @version 02-Jun-2016
*/
public class AesCipherTest {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testCipherManagerImplStringDiffKey() {
final AbstractCipher cipherManager = CipherCreator.instance().create("secret-key");
final String encrypted = cipherManager.encrypt("test-encrypt");
- Assert.assertEquals(encrypted, encrypted);
+ Assert.assertEquals(encrypted, null);
}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 03-Jun-2016
+ * @version 03-Jun-2016
*/
@RunWith(JMockit.class)
public class Sha256Test {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 08-Jun-2016
+ * @version 08-Jun-2016
*/
@RunWith(JMockit.class)
public class RestUtilsTest {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 08-Jun-2016
+ * @version 08-Jun-2016
*/
@RunWith(JMockit.class)
@NotThreadSafe
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ Copyright 2016 Huawei Technologies Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ Copyright 2016 Huawei Technologies Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
<version>4.8.2</version>
</dependency>
<dependency>
- <groupId>org.jmockit</groupId>
+ <groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
- <version>1.19</version>
+ <version>1.1</version>
</dependency>
</dependencies>
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class ExceptionArgs {
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
public ExceptionArgs() {
// default constructor.
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param descArgs: descriptions.
* @param reasonArgs: reasons.
* @param detailArgs: details.
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class ServiceException extends Exception {
* This method is only used as deserialized, in other cases, use parameterized constructor.
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
public ServiceException() {
super("");
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: details.
* @param cause: reason.
*/
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param message: details.
*/
public ServiceException(final String message) {
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param message: details.
*/
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param httpCode: http status code.
*/
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param httpCode: http code.
* @param exceptionArgs: Exception handling frame parameters.
* Have a placeholder exception, use args formatted message.
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param message: details.
* @param args: Placeholders for parameters
* Have a placeholder exception, use args formatted message
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param message: details.
* @param cause: reason.
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param id: exception id.
* @param message: details.
* @param cause: reason.
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param cause: reason.
*/
public ServiceException(final Throwable cause) {
* Get exceptoin id.<br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public String getId() {
if(id == null || id.isEmpty()) {
* Obtain the ROA exception handling framework parameters<br/>
*
* @return exception args.
- * @since SDNO 0.5
+ * @since
*/
public ExceptionArgs getExceptionArgs() {
return exceptionArgs;
* Gets the parameter information<br/>
*
* @return parameter list.
- * @since SDNO 0.5
+ * @since
*/
protected Object[] getArgs() {
if(args == null || args.length == 0 || DEFAULT_ID.equals(getId())) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 31-May-2016
+ * @version 31-May-2016
*/
public class ReaderHelper {
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param reader
*/
public ReaderHelper(final Reader reader) {
* Gets the next line.<br/>
*
* @return line if present else null.
- * @since SDNO 0.5
+ * @since
*/
public String getLine() {
if(ite != null && ite.hasNext()) {
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openo.baseservice.roa.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Enumeration;
-import java.util.Properties;
-
-/**
- * Service connection configuration util.<br/>
- * <p>
- * Get host and port from the Client Configure the connection environment and service Configure
- * profile
- * </p>
- *
- * @author
- * @version SDNO 0.5 28-May-2016
- */
-public class ServiceUtil {
-
- private static final Logger LOG = LoggerFactory.getLogger(ServiceUtil.class);
-
- private final Properties allConfigure = new Properties();
-
- private final Properties serviceConfigure;
-
- private String serviceStage;
-
- private String serviceName;
-
- /**
- * Constructor<br/>
- * <p>
- * Load profile information.
- * </p>
- *
- * @since SDNO 0.5
- * @param serviceName user-specified service name.
- * @param url invoked service url.
- */
- public ServiceUtil(final String serviceName, final String url) {
- final String fomattedUrl = formatUrl(url);
- serviceConfigure = loadProperties("service-configure.properties");
- if(null == serviceName || serviceName.isEmpty()) {
- this.serviceName = getServiceNameWhitUrl(fomattedUrl);
- } else {
- this.serviceName = serviceName;
- }
- loadPropertyFile();
- }
-
- /**
- * Get the service user-specified host.
- * <br/>
- *
- * @return host
- * @since SDNO 0.5
- */
- public String getServiceHost() {
- final String host = allConfigure.getProperty(serviceName + "." + serviceStage + ".host");
- if(null == host) {
- return "";
- }
- return host;
- }
-
- /**
- * Get the service user-specified port.
- * <br/>
- *
- * @return port
- * @since SDNO 0.5
- */
- public int getServicePort() {
- final String portStr = allConfigure.getProperty(serviceName + "." + serviceStage + ".port");
- if(null == portStr) {
- return -1;
- }
- return Integer.parseInt(portStr);
- }
-
- private String getServiceNameWhitUrl(final String url) {
- final Enumeration<?> keys = serviceConfigure.propertyNames();
- while(keys.hasMoreElements()) {
- final String key = (String)keys.nextElement();
- if(key.endsWith("urls")) {
- final String urls = serviceConfigure.getProperty(key);
- for(String tempUrl : urls.split(",")) {
- tempUrl = formatUrl(tempUrl);
- if(url.startsWith(tempUrl)) {
- return key.split("\\.")[0];
- }
- }
-
- }
- }
- return "";
- }
-
- private static String formatUrl(final String url) {
- String outUrl = url;
- if(outUrl.contains("?")) {
- outUrl = outUrl.split("\\?")[0];
- }
- outUrl = outUrl.replace("\\", "/");
- outUrl = outUrl.replaceAll("[/]{2,}", "/");
- outUrl = outUrl.endsWith("/") ? outUrl.substring(0, outUrl.length() - 1) : outUrl;
- outUrl = outUrl.endsWith("/*") ? outUrl.substring(0, outUrl.length() - 2) : outUrl;
- return outUrl;
- }
-
- /**
- * Loads the client and service configuration files.
- * <br/>
- *
- * @since SDNO 0.5
- */
- private void loadPropertyFile() {
- final Properties clientConfigure = loadProperties(serviceName + "-client-configure.properties");
- allConfigure.putAll(clientConfigure);
- allConfigure.putAll(serviceConfigure);
- serviceStage = allConfigure.getProperty(serviceName + ".stage");
- }
-
- /**
- * Loads the client and service configuration files.
- * <br/>
- *
- * @param classProperties: service profile file name.
- * @return Service configuration.
- * @since SDNO 0.5
- */
- private Properties loadProperties(final String classProperties) {
- final Properties properties = new Properties();
- InputStream inputStream = null;
- ClassLoader classloader = null;
- try {
- classloader = this.getClass().getClassLoader();
- if(classloader != null) {
- inputStream = classloader.getResourceAsStream(classProperties);
- }
- if(inputStream != null) {
- properties.load(inputStream);
- inputStream.close();
- }
- } catch(final IOException e) {
- LOG.error("load file error: ", e);
- } finally {
- if(inputStream != null) {
- try {
- inputStream.close();
- } catch(final IOException ee) {
- LOG.error("close inputStream error: ", ee);
- }
- inputStream = null;
- }
- }
- return properties;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openo.baseservice.roa.util.clientsdk;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Collection;
-import java.util.Date;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Http utilities.
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 28-May-2016
- */
-public class HttpUtil {
-
- /**
- *
- */
- private static final String APPLICATION_JSON = "application/json";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtil.class);
-
- private HttpUtil() {
-
- }
-
- /**
- * Check if the given array contains the given value (with case-insensitive comparison).
- * <br/>
- *
- * @param array The array
- * @param value The value to search
- * @return true if the array contains the value
- * @since SDNO 0.5
- */
- public static boolean containsIgnoreCase(final String[] array, final String value) {
- for(final String str : array) {
- if(value == null && str == null) {
- return true;
- }
- if(value != null && value.equalsIgnoreCase(str)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Join an array of strings with the given separator.
- * <br/>
- *
- * @param array The array of strings
- * @param separator The separator
- * @return the resulting string
- * @since SDNO 0.5
- */
- public static String join(final String[] array, final String separator) {
- final int len = array.length;
- if(len == 0) {
- return "";
- }
- final StringBuilder out = new StringBuilder();
- out.append(array[0]);
- for(int i = 1; i < len; i++) {
- out.append(separator).append(array[i]);
- }
- return out.toString();
- }
-
- /**
- * Format the given parameter object into string.
- * <br/>
- *
- * @param param param input
- * @return query param string
- * @since SDNO 0.5
- */
- public static String parameterToString(final Object param) {
- if(param == null) {
- return "";
- } else if(param instanceof Date) {
- return Long.toString(((Date)param).getTime());
- } else if(param instanceof Collection) {
- final StringBuilder b = new StringBuilder();
- for(final Object o : (Collection)param) {
- if(b.length() > 0) {
- b.append(',');
- }
- b.append(String.valueOf(o));
- }
- return b.toString();
- } else {
- return String.valueOf(param);
- }
- }
-
- /**
- * get accept header
- * <br/>
- *
- * @param accepts accepts accept types
- * @return the accepts string
- * @since SDNO 0.5
- */
- public static String selectHeaderAccept(final String[] accepts) {
- if(accepts.length == 0) {
- return null;
- }
- if(HttpUtil.containsIgnoreCase(accepts, APPLICATION_JSON)) {
- return APPLICATION_JSON;
- }
- return HttpUtil.join(accepts, ",");
- }
-
- /**
- * select head content type
- * <br/>
- *
- * @param contentTypes contentTypes content types
- * @return the json string or the first content type
- * @since SDNO 0.5
- */
- public static String selectHeaderContentType(final String[] contentTypes) {
- if(contentTypes.length == 0) {
- return APPLICATION_JSON;
- }
- if(HttpUtil.containsIgnoreCase(contentTypes, APPLICATION_JSON)) {
- return APPLICATION_JSON;
- }
- return contentTypes[0];
- }
-
- /**
- * Escape the given string to be used as URL query value.<br/>
- *
- * @param str str param str
- * @return escape string
- * @since SDNO 0.5
- */
- public static String escapeString(final String str) {
- try {
- return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
- } catch(final UnsupportedEncodingException e) {
- LOGGER.info("UTF8 is not supported", e);
- return str;
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openo.baseservice.roa.util.clientsdk;
-
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-
-import net.sf.json.JSON;
-
-import java.io.IOException;
-
-/**
- * JSON parse utilities.
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 28-May-2016
- */
-public final class JsonUtil {
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- static {
- MAPPER.setDeserializationConfig(MAPPER.getDeserializationConfig()
- .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES));
- }
-
- private JsonUtil() {
- }
-
- /**
- * Parse JSON formated string.<br/>
- *
- * @param jsonstr: JSON formated string.
- * @param type: result type.
- * @return parsed object.
- * @throws IOException incase error.
- * @since SDNO 0.5
- */
- public static <T> T unMarshal(final String jsonstr, final Class<T> type) throws IOException {
- return MAPPER.readValue(jsonstr, type);
- }
-
- /**
- * Parse JSON formatted string (for a generic target type).
- * <br/>
- *
- * @param jsonstr request data.
- * @param type target type.
- * @return result object.
- * @throws IOException incase error.
- * @since SDNO 0.5
- */
- public static <T> T unMarshal(final String jsonstr, final TypeReference<T> type) throws IOException {
- return MAPPER.readValue(jsonstr, type);
- }
-
- /**
- * Convert object to JSON format string.
- * <br/>
- *
- * @param srcObj source object.
- * @return JSON format string.
- * @throws IOException incase of error.
- * @since SDNO 0.5
- */
- public static String marshal(final Object srcObj) throws IOException {
- if(srcObj instanceof JSON) {
- return srcObj.toString();
- }
- return MAPPER.writeValueAsString(srcObj);
- }
-
- /**
- * Get parsing mapper
- * <br/>
- *
- * @return parsing mapper
- * @since SDNO 0.5
- */
- public static ObjectMapper getMapper() {
- return MAPPER;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openo.baseservice.roa.util.clientsdk;
-
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.restclient.Restful;
-import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback;
-import org.openo.baseservice.roa.util.restclient.RestfulParametes;
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Rest Client Tools.
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 28-May-2016
- */
-public class RestClientUtil {
-
- private static Set<Class<?>> ret = new HashSet<>();
-
- static {
- ret.add(Boolean.class);
- ret.add(Character.class);
- ret.add(Byte.class);
- ret.add(Short.class);
- ret.add(Integer.class);
- ret.add(Long.class);
- ret.add(Float.class);
- ret.add(Double.class);
- ret.add(Void.class);
- ret.add(String.class);
- }
-
- private RestClientUtil() {
-
- }
-
- /**
- * Processing HTTP requests.
- * <br/>
- *
- * @param method method name.
- * @param path request path.
- * @param parameters parameters.
- * @param restFull ReST request instance
- * @return The ReST response.
- * @throws ServiceException Exception information.
- * @since SDNO 0.5
- */
- public static RestfulResponse invokeMethod(final String method, final String path,
- final RestfulParametes parameters, final Restful restFull) throws ServiceException {
- RestfulResponse response;
- if("get".equalsIgnoreCase(method)) {
- response = restFull.get(path, parameters);
- } else if("put".equalsIgnoreCase(method)) {
- response = restFull.put(path, parameters);
- } else if("post".equalsIgnoreCase(method)) {
- response = restFull.post(path, parameters);
- } else if("delete".equalsIgnoreCase(method)) {
- response = restFull.delete(path, parameters);
- } else if("patch".equalsIgnoreCase(method)) {
- response = restFull.patch(path, parameters);
- } else {
- throw new ServiceException("NotSuppertMethod", 400);
- }
- return response;
- }
-
- /**
- * An asynchronous HTTP request.
- * <br/>
- *
- * @param method http method.
- * @param path request path.
- * @param parameters request parameters.
- * @param restFull restFull instance.
- * @param callback callback function.
- * @throws ServiceException in case error.
- * @since SDNO 0.5
- */
- public static void invokeAsyncMethod(final String method, final String path, final RestfulParametes parameters,
- final Restful restFull, final RestfulAsyncCallback callback) throws ServiceException {
- if("get".equalsIgnoreCase(method)) {
- restFull.asyncGet(path, parameters, callback);
- } else if("put".equalsIgnoreCase(method)) {
- restFull.asyncPut(path, parameters, callback);
- } else if("post".equalsIgnoreCase(method)) {
- restFull.asyncPost(path, parameters, callback);
- } else if("delete".equalsIgnoreCase(method)) {
- restFull.asyncDelete(path, parameters, callback);
- } else if("patch".equalsIgnoreCase(method)) {
- restFull.asyncPatch(path, parameters, callback);
- } else {
- throw new ServiceException("NotSuppertMethod", 400);
- }
- }
-
- /**
- * Determine whether a class is a native.<br/>
- *
- * @param clazz: class type.
- * @return whether primitive or not.
- * @since SDNO 0.5
- */
- public static boolean isPrimitive(final Class<?> clazz) {
- if(clazz.isPrimitive()) {
- return true;
- }
- if(ret.contains(clazz)) {
- return true;
- }
- return false;
- }
-}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class DefaultAsyncCallback implements RestfulAsyncCallback {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
import org.eclipse.jetty.client.HttpExchange;
import org.eclipse.jetty.http.HttpMethods;
import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.ServiceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* </p>
*
* @author
- * @version SDNO 0.5 Aug 9, 2016
+ * @version Aug 9, 2016
*/
public abstract class HttpBaseRest implements Restful {
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
public HttpBaseRest() {
super();
* @param callback
* @return
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
protected RestfulResponse sendHttpRequest(final String method, final String servicePath,
final RestfulParametes restParametes, final RestfulOptions options, final RestfulAsyncCallback callback)
} else {
String host = defaultIP;
int iPort = defaultPort;
- String calledServiceName = null;
- if(options != null) {
- calledServiceName = options.getCalledServicName();
- }
- final ServiceUtil serviceUtil = new ServiceUtil(calledServiceName, url.toString());
- final String configHost = serviceUtil.getServiceHost();
- final int configPort = serviceUtil.getServicePort();
- if(!configHost.isEmpty() && configPort > 0) {
- if(options != null) {
- options.setHost(configHost);
- options.setPort(configPort);
- } else {
- host = configHost;
-
- iPort = configPort;
- }
- }
if(options != null) {
host = options.getHost();
if(host.isEmpty()) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 Aug 9, 2016
+ * @version Aug 9, 2016
*/
public class HttpRest extends HttpBaseRest {
*
* @param options: rest options.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
public void initHttpRest(final RestfulOptions option) throws ServiceException {
if(option == null) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestHttpContentExchange extends ContentExchange {
* <p>
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param cacheFields whether to cache response header.
* @param asyncCallback callback method.
*/
* @param data GZipped data.
* @return Uncompressed data.
* @throws IOException
- * @since SDNO 0.5
+ * @since
*/
public String decompressGzipToStr(final byte[] data) throws IOException {
if(data == null) {
* @param name buffer
* @param value value
* @throws IOException
- * @since SDNO 0.5
+ * @since
*/
@Override
protected synchronized void onResponseHeader(final Buffer name, final Buffer value) throws IOException {
*
* @return response object.
* @throws IOException
- * @since SDNO 0.5
+ * @since
*/
public RestfulResponse getResponse() throws IOException {
final RestfulResponse rsp = new RestfulResponse();
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public interface Restful {
* @param restParametes: query parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse get(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse head(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncGet(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
throws ServiceException;
* @param options: request options.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncGet(String servicePath, RestfulParametes restParametes, RestfulOptions options,
RestfulAsyncCallback callback) throws ServiceException;
* @param restParametes: request parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse put(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse put(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPut(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
throws ServiceException;
* @param options: request options.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPut(String servicePath, RestfulParametes restParametes, RestfulOptions options,
RestfulAsyncCallback callback) throws ServiceException;
* @param restParametes: request parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse post(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse post(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPost(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
throws ServiceException;
* @param options: request options.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options,
RestfulAsyncCallback callback) throws ServiceException;
* @param restParametes: request parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse delete(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
throws ServiceException;
* @param options: request options.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulOptions options,
RestfulAsyncCallback callback) throws ServiceException;
* @param restParametes: request parameters.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse patch(String servicePath, RestfulParametes restParametes) throws ServiceException;
* @param options: request options.
* @return response.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
RestfulResponse patch(String servicePath, RestfulParametes restParametes, RestfulOptions options)
throws ServiceException;
* @param restParametes: request parameters.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
throws ServiceException;
* @param options: request options.
* @param callback: response callback method.
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulOptions options,
RestfulAsyncCallback callback) throws ServiceException;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public interface RestfulAsyncCallback {
* Response callback.<br/>
*
* @param response: response of ReST call.
- * @since SDNO 0.5
+ * @since
*/
void callback(RestfulResponse response);
* Exceptoin callback.<br/>
*
* @param e: ReST call exception.
- * @since SDNO 0.5
+ * @since
*/
void handleExcepion(Throwable e);
}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestfulClientConst {
public static final String SERVER_KEY_NAME = "defaulServer";
- public static final String CALLED_SERVICE_NAME = "serviceName";
-
public static final String HOST_KEY_NAME = "host";
public static final String PORT_KEY_NAME = "port";
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestfulConfigure {
* Use the default path initialization http Rest options.
* </p>
*
- * @since SDNO 0.5
+ * @since
*/
public RestfulConfigure() {
final String config = "/etc/conf/restclient.json";
* Use the specified file to initialize http Rest options.
* </p>
*
- * @since SDNO 0.5
+ * @since
* @param configfile
*/
public RestfulConfigure(final String configfile) {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestfulFactory {
*
* @param protocol protocol. currently only support 'http'.
* @return restful instance.
- * @since SDNO 0.5
+ * @since
*/
public static synchronized Restful getRestInstance(final String protocol) {
Restful rest = INSTANCES.get(protocol);
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestfulOptions {
private final Map<String, Object> optionsMap = new HashMap<>();
- /**
- * Set called service name.<br/>
- *
- * @param serviceName service name.
- * @return true.
- * @since SDNO 0.5
- */
- public boolean setCalledServiceName(final String serviceName) {
- this.setOption(RestfulClientConst.CALLED_SERVICE_NAME, serviceName);
- return true;
- }
-
- /**
- * Get called service name.<br/>
- *
- * @return
- * @since SDNO 0.5
- */
- public String getCalledServicName() {
- final Object obj = this.getOption(RestfulClientConst.CALLED_SERVICE_NAME);
- if(null == obj) {
- return "";
- }
- return (String)obj;
- }
-
/**
* Get port.<br/>
*
* @return port.
- * @since SDNO 0.5
+ * @since
*/
public int getPort() {
final Object obj = this.getOption(RestfulClientConst.PORT_KEY_NAME);
*
* @param port port to set.
* @return
- * @since SDNO 0.5
+ * @since
*/
public boolean setPort(final int port) {
this.setOption(RestfulClientConst.PORT_KEY_NAME, port);
* Get host.<br/>
*
* @return the host.
- * @since SDNO 0.5
+ * @since
*/
public String getHost() {
final Object obj = this.getOption(RestfulClientConst.HOST_KEY_NAME);
*
* @param host host to set.
* @return
- * @since SDNO 0.5
+ * @since
*/
public boolean setHost(final String host) {
this.setOption(RestfulClientConst.HOST_KEY_NAME, host);
*
* @param timeout time-out to set in seconds.
* @return
- * @since SDNO 0.5
+ * @since
*/
public boolean setRestTimeout(final int timeout) {
if(0 < timeout && REST_OPTIONS_TIMEOUT_MAXTIMEOUT >= timeout) {
* Get time-out.<br/>
*
* @return time-out in seconds.
- * @since SDNO 0.5
+ * @since
*/
public int getRestTimeout() {
final Object obj = this.getOption(REST_OPTIONS_NAME_TIMEOUT);
*
* @param optionName option name.
* @return option
- * @since SDNO 0.5
+ * @since
*/
public Object getOption(final String optionName) {
return optionsMap.get(optionName);
*
* @param optionName option name.
* @return option value as int.
- * @since SDNO 0.5
+ * @since
*/
public int getIntOption(final String optionName) {
final Object obj = this.getOption(optionName);
*
* @param optionName option name.
* @return option value as string.
- * @since SDNO 0.5
+ * @since
*/
public String getStringOption(final String optionName) {
final Object obj = this.getOption(optionName);
* @param option option name.
* @param optionsValue option value.
* @return
- * @since SDNO 0.5
+ * @since
*/
public Object setOption(final String option, final Object optionsValue) {
return optionsMap.put(option, optionsValue);
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 Aug 9, 2016
+ * @version Aug 9, 2016
*/
public class RestfulParametes {
*
* @param key
* @return
- * @since SDNO 0.5
+ * @since
*/
public String get(final String key) {
return paramMap.get(key);
* <br/>
*
* @param data
- * @since SDNO 0.5
+ * @since
*/
public void setRawData(final String data) {
this.rawData = data;
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public String getRawData() {
return this.rawData;
* @param key
* @param value
* @return
- * @since SDNO 0.5
+ * @since
*/
public String put(final String key, final String value) {
return paramMap.put(key, value);
* @param key
* @param value
* @return
- * @since SDNO 0.5
+ * @since
*/
public String putHttpContextHeader(final String key, final String value) {
return headerMap.put(key, value);
* @param key
* @param value
* @return
- * @since SDNO 0.5
+ * @since
*/
public String putHttpContextHeader(final String key, final int value) {
return this.putHttpContextHeader(key, String.valueOf(value));
*
* @param key
* @return
- * @since SDNO 0.5
+ * @since
*/
public String getHttpContextHeader(final String key) {
return headerMap.get(key);
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public Map<String, String> getParamMap() {
return paramMap;
* <br/>
*
* @param paramMap
- * @since SDNO 0.5
+ * @since
*/
public void setParamMap(final Map<String, String> paramMap) {
this.paramMap = paramMap;
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public Map<String, String> getHeaderMap() {
return this.headerMap;
* <br/>
*
* @param headerMap
- * @since SDNO 0.5
+ * @since
*/
public void setHeaderMap(final Map<String, String> headerMap) {
this.headerMap = headerMap;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* </p>
*
* @author
- * @version SDNO 0.5 28-May-2016
+ * @version 28-May-2016
*/
public class RestfulResponse {
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public int getStatus() {
return status;
* <br/>
*
* @param status
- * @since SDNO 0.5
+ * @since
*/
public void setStatus(final int status) {
this.status = status;
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public Map<String, String> getRespHeaderMap() {
return respHeaderMap;
* <br/>
*
* @param header
- * @since SDNO 0.5
+ * @since
*/
public void setRespHeaderMap(final Map<String, String> header) {
this.respHeaderMap = header;
*
* @param key header param name.
* @return header param value as integer. (-1 if error)
- * @since SDNO 0.5
+ * @since
*/
public int getRespHeaderInt(final String key) {
if(respHeaderMap != null) {
*
* @param key header param name.
* @return value as long. -1 if no value.
- * @since SDNO 0.5
+ * @since
*/
public long getRespHeaderLong(final String key) {
if(respHeaderMap != null) {
*
* @param key header name.
* @return header value.
- * @since SDNO 0.5
+ * @since
*/
public String getRespHeaderStr(final String key) {
if(respHeaderMap != null) {
* <br/>
*
* @return
- * @since SDNO 0.5
+ * @since
*/
public String getResponseContent() {
return responseContent;
* <br/>
*
* @param responseString
- * @since SDNO 0.5
+ * @since
*/
public void setResponseJson(final String responseString) {
this.responseContent = responseString;
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 12-Jun-2016
+ * @version 12-Jun-2016
*/
public class ReaderHelperTest {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 13-Jun-2016
+ * @version 13-Jun-2016
*/
public class TestServiceUtil {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetServiceHost() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetServicePort() {
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.baseservice.roa.util.clientsdk;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Arrays;
-import java.util.Date;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import mockit.Mocked;
-import mockit.NonStrictExpectations;
-
-/**
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 13-Jun-2016
- */
-public class TestHttpUtil {
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @Before
- public void setUp() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @After
- public void tearDown() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testContainsIgnoreCase() {
- final String[] array = {"hello", "how", "are", "you", "?"};
- final String toFind = "Hello";
- Assert.assertTrue(HttpUtil.containsIgnoreCase(array, toFind));
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testContainsIgnoreCaseNull() {
- final String[] array = {"hello", "how", "are", "you", "?"};
- final String toFind = "Hello";
- Assert.assertFalse(HttpUtil.containsIgnoreCase(array, null));
-
- array[0] = null;
- Assert.assertFalse(HttpUtil.containsIgnoreCase(array, toFind));
-
- Assert.assertTrue(HttpUtil.containsIgnoreCase(array, null));
- array[0] = "hello";
- array[array.length - 1] = null;
- Assert.assertTrue(HttpUtil.containsIgnoreCase(array, null));
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testJoin() {
- final String[] array = {"hello", "how", "are", "you", "?"};
- String actual = HttpUtil.join(array, ",");
- String expected = "hello,how,are,you,?";
- Assert.assertEquals(actual, expected);
-
- actual = HttpUtil.join(array, "#");
- expected = expected.replaceAll(",", "#");
- Assert.assertEquals(actual, expected);
- actual = HttpUtil.join(new String[] {}, ",");
- Assert.assertEquals(actual, "");
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testParameterToString() {
- // with param string.
- Object param = new String("String Param");
- String actual = HttpUtil.parameterToString(param);
- String expected = "String Param";
- Assert.assertEquals(expected, actual);
-
- // with param date.
- final Date date = new Date();
- param = date;
- expected = "" + date.getTime();
- actual = HttpUtil.parameterToString(param);
- Assert.assertEquals(expected, actual);
-
- // with param collection.
- final String[] array = {"hello", "how", "are", "you", "?"};
- param = Arrays.asList(array);
- expected = HttpUtil.join(array, ",");
- actual = HttpUtil.parameterToString(param);
- Assert.assertEquals(expected, actual);
-
- // with param any
- param = new Object() {
-
- @Override
- public String toString() {
- return "test object";
- }
- };
- expected = "test object";
- actual = HttpUtil.parameterToString(param);
- Assert.assertEquals(expected, actual);
-
- // with param null.
- expected = "";
- actual = HttpUtil.parameterToString(null);
- Assert.assertEquals(expected, actual);
-
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testSelectHeaderAccept() {
- final String[] accepts = {"application/json", "text/plain", "application/xml"};
- String expected = "application/json";
- String actual = HttpUtil.selectHeaderAccept(accepts);
- Assert.assertEquals(expected, actual);
-
- accepts[0] = "application/x-www-form-urlencoded";
- expected = HttpUtil.join(accepts, ",");
- actual = HttpUtil.selectHeaderAccept(accepts);
- Assert.assertEquals(expected, actual);
-
- expected = null;
- actual = HttpUtil.selectHeaderAccept(new String[] {});
- Assert.assertEquals(expected, actual);
-
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testSelectHeaderContentType() {
- final String[] accepts = {"application/json", "text/plain", "application/xml"};
- String expected = "application/json";
- String actual = HttpUtil.selectHeaderContentType(accepts);
- Assert.assertEquals(expected, actual);
-
- accepts[0] = "application/x-www-form-urlencoded";
- expected = "application/x-www-form-urlencoded";
- actual = HttpUtil.selectHeaderContentType(accepts);
- Assert.assertEquals(expected, actual);
-
- expected = "application/json";
- actual = HttpUtil.selectHeaderContentType(new String[] {});
- Assert.assertEquals(expected, actual);
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testEscapeString() throws Exception {
- final String str = "/this/url/to be encoded";
- final String actual = HttpUtil.escapeString(str);
- final String expected = "%2Fthis%2Furl%2Fto%20be%20encoded";
- Assert.assertEquals(expected, actual);
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Ignore
- @Test
- public void testEscapeStringException() throws Exception {
-
- final String str = "/this/url/to be encoded";
- new NonStrictExpectations() {
-
- @Mocked
- URLEncoder encoder;
-
- {
- URLEncoder.encode(str, "utf8");
- result = new UnsupportedEncodingException();
- }
- };
-
- final String actual = HttpUtil.escapeString(str);
- Assert.assertEquals(str, actual);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.baseservice.roa.util.clientsdk;
-
-import org.openo.baseservice.roa.util.clientsdk.demo.JsonTestClass;
-
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import net.sf.json.JSONObject;
-
-import junit.framework.Assert;
-
-/**
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 13-Jun-2016
- */
-public class TestJsonUtil {
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @Before
- public void setUp() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @After
- public void tearDown() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testUnMarshalStringClassOfT() throws Exception {
- final String name = "myname";
- final int id = 25;
- final String jsonstr = "{\"name\": \"" + name + "\", \"id\": " + id + "}";
-
- final JsonTestClass jsonObj = JsonUtil.unMarshal(jsonstr, JsonTestClass.class);
-
- Assert.assertNotNull(jsonObj);
- Assert.assertEquals(name, jsonObj.getName());
- Assert.assertEquals(id, jsonObj.getId());
-
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testUnMarshalStringTypeReferenceOfT() throws Exception {
- final String name = "myname";
- final int id = 25;
- final String jsonstr = "{\"name\": \"" + name + "\", \"id\": " + id + "}";
-
- final JsonTestClass jsonObj = JsonUtil.unMarshal(jsonstr, new TypeReference<JsonTestClass>() {});
-
- Assert.assertNotNull(jsonObj);
- Assert.assertEquals(name, jsonObj.getName());
- Assert.assertEquals(id, jsonObj.getId());
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testMarshal() throws Exception {
- final JsonTestClass jsonObj = new JsonTestClass();
- jsonObj.setId(1);
- jsonObj.setName("somename");
- final String str = JsonUtil.marshal(jsonObj);
- final JSONObject json = JSONObject.fromObject(str);
- Assert.assertNotNull(json);
- Assert.assertEquals(json.getString("name"), jsonObj.getName());
- Assert.assertEquals(json.getInt("id"), jsonObj.getId());
-
- }
-
- /**
- * <br/>
- *
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testMarshalJsonObj() throws Exception {
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("id", 10);
- jsonObj.put("name", "some-name");
- final String str = JsonUtil.marshal(jsonObj);
- final JSONObject json = JSONObject.fromObject(str);
- Assert.assertNotNull(json);
- Assert.assertEquals(json.getString("name"), "some-name");
- Assert.assertEquals(json.getInt("id"), 10);
-
- }
-
- /**
- * <br/>
- *
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws Exception
- * @since SDNO 0.5
- */
- @Test
- public void testGetMapper() throws JsonParseException, JsonMappingException, Exception {
- final String name = "myname";
- final int id = 25;
- final ObjectMapper mapper = JsonUtil.getMapper();
- Assert.assertNotNull(mapper);
- final JSONObject json = new JSONObject();
- json.put("name", name);
- json.put("id", id);
- final JsonTestClass jsonObj = mapper.readValue(json.toString(), JsonTestClass.class);
- Assert.assertNotNull(jsonObj);
- Assert.assertEquals(name, jsonObj.getName());
- Assert.assertEquals(id, jsonObj.getId());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.baseservice.roa.util.clientsdk;
-
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.restclient.Restful;
-import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback;
-import org.openo.baseservice.roa.util.restclient.RestfulParametes;
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import java.util.Arrays;
-import java.util.Date;
-
-import junit.framework.Assert;
-import mockit.Expectations;
-import mockit.Mocked;
-
-/**
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 13-Jun-2016
- */
-public class TestRestClientUtil {
-
- @Mocked
- Restful restFullMock;
-
- ExpectedException thrown = ExpectedException.none();;
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @Before
- public void setUp() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws java.lang.Exception
- * @since SDNO 0.5
- */
- @After
- public void tearDown() throws Exception {
- }
-
- /**
- * <br/>
- *
- * @throws ServiceException
- * @since SDNO 0.5
- */
- @Ignore
- @Test
- public void testInvokeMethod() throws ServiceException {
- final String path = "test/path";
- final RestfulParametes parameters = null;
- final RestfulResponse expected = new RestfulResponse();
- expected.setStatus(200);
-
- new Expectations() {
-
- {
- restFullMock.get(path, parameters);
- returns(expected);
-
- restFullMock.post(path, parameters);
- returns(expected);
-
- restFullMock.patch(path, parameters);
- returns(expected);
-
- restFullMock.delete(path, parameters);
- returns(expected);
-
- restFullMock.put(path, parameters);
- returns(expected);
- }
- };
- RestfulResponse actual = RestClientUtil.invokeMethod("GET", path, parameters, restFullMock);
- Assert.assertEquals(200, actual.getStatus());
-
- actual = RestClientUtil.invokeMethod("POST", path, parameters, restFullMock);
- Assert.assertEquals(200, actual.getStatus());
-
- actual = RestClientUtil.invokeMethod("PATCH", path, parameters, restFullMock);
- Assert.assertEquals(200, actual.getStatus());
-
- actual = RestClientUtil.invokeMethod("DELETE", path, parameters, restFullMock);
- Assert.assertEquals(200, actual.getStatus());
-
- actual = RestClientUtil.invokeMethod("PUT", path, parameters, restFullMock);
- Assert.assertEquals(200, actual.getStatus());
- }
-
- @Ignore
- @Test(expected = ServiceException.class)
- public void testInvokeMethodException() throws ServiceException {
- RestClientUtil.invokeMethod("UNKNOWN-METHOD", "some/path", null, restFullMock);
- }
-
- /**
- * <br/>
- *
- * @throws ServiceException
- * @since SDNO 0.5
- */
- @Ignore
- @Test(expected = ServiceException.class)
- public void testInvokeAsyncMethod() throws ServiceException {
- final String path = "test/path";
- final RestfulParametes parameters = null;
- final RestfulAsyncCallback callback = null;
-
- RestClientUtil.invokeAsyncMethod("GET", path, parameters, restFullMock, callback);
-
- RestClientUtil.invokeAsyncMethod("POST", path, parameters, restFullMock, callback);
-
- RestClientUtil.invokeAsyncMethod("PATCH", path, parameters, restFullMock, callback);
-
- RestClientUtil.invokeAsyncMethod("DELETE", path, parameters, restFullMock, callback);
-
- RestClientUtil.invokeAsyncMethod("PUT", path, parameters, restFullMock, callback);
-
- RestClientUtil.invokeAsyncMethod("UNKNOWN", path, parameters, restFullMock, callback);
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Ignore
- @Test
- public void testIsPrimitive() {
-
- Assert.assertTrue(RestClientUtil.isPrimitive(Integer.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Long.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Double.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Void.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(String.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Boolean.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Byte.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Character.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Short.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(Float.class));
-
- Assert.assertTrue(RestClientUtil.isPrimitive(int.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(long.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(double.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(void.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(boolean.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(byte.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(char.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(short.class));
- Assert.assertTrue(RestClientUtil.isPrimitive(float.class));
-
- Assert.assertFalse(RestClientUtil.isPrimitive(Object.class));
- Assert.assertFalse(RestClientUtil.isPrimitive(Date.class));
- Assert.assertFalse(RestClientUtil.isPrimitive(Arrays.class));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.baseservice.roa.util.clientsdk.demo;
-
-/**
- * <br/>
- * <p>
- * </p>
- *
- * @author
- * @version SDNO 0.5 13-Jun-2016
- */
-public class JsonTestClass {
-
- /**
- *
- */
- private String name;
-
- /**
- *
- */
- private int id;
-
- /**
- * Constructor<br/>
- * <p>
- * </p>
- *
- * @since SDNO 0.5
- */
- public JsonTestClass() {
- }
-
- /**
- * <br/>
- *
- * @return
- * @since SDNO 0.5
- */
- public String getName() {
- return name;
- }
-
- /**
- * <br/>
- *
- * @param name
- * @since SDNO 0.5
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * <br/>
- *
- * @return
- * @since SDNO 0.5
- */
- public int getId() {
- return id;
- }
-
- /**
- * <br/>
- *
- * @param id
- * @since SDNO 0.5
- */
- public void setId(int id) {
- this.id = id;
- }
-}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.ServiceUtil;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.net.URLEncoder;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpExchange;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
-import java.net.URLEncoder;
-
-import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
import mockit.Mocked;
* </p>
*
* @author
- * @version SDNO 0.5 13-Jun-2016
+ * @version 13-Jun-2016
*/
@RunWith(JMockit.class)
public class TestHttpRest {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRest() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRestExcpetion() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRestNull() throws Exception {
*
* @throws NoSuchFieldException
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testCreateRestHttpContentExchange() throws NoSuchFieldException, Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStringRestfulParametes() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStringRestfulParametesRestfulOptions() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testGetStringRestfulParametesEncodeError() throws Exception {
final RestfulOptions options = new RestfulOptions();
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testHeadStringRestfulParametes() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testHeadStringRestfulParametesRestfulOptions() throws Exception {
final RestfulOptions options = new RestfulOptions();
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.head("path/to/service", parametes, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* @param options
* @return
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
private HttpRest getHttpRest(final RestfulOptions options) throws ServiceException {
final HttpRest httpRest = new HttpRest();
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncGetStringRestfulParametesRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncGetStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPutStringRestfulParametes() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(-1);
- }
-
- };
final RestfulResponse response = httpRest.put("path/to/service", parametes);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPutStringRestfulParametesRestfulOptions() throws ServiceException {
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.put("path/to/service", parametes, null);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPutStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPutStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testPostStringRestfulParametes() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPostStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
thrown.expect(ServiceException.class);
thrown.expectMessage("request is exception");
final RestfulResponse response = httpRest.post("path/to/service", parameters, null);
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPostStringRestfulParametesRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPostStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testDeleteStringRestfulParametes() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testDeleteStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.delete("path/to/service", parameters, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncDeleteStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncDeleteStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPatchStringRestfulParametes() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.patch("path/to/service", parameters);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPatchStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.patch("path/to/service", parameters, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPatchStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPatchStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 20-Jun-2016
+ * @version 20-Jun-2016
*/
@RunWith(JMockit.class)
public class TestRestHttpContentExchange {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
* <br/>
*
* @throws IOException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnRequestCommitted() throws IOException {
* <br/>
*
* @throws IOException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnRequestComplete() throws IOException {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnResponseComplete() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testDecompressGzipToStr() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testDecompressGzipToStrException() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testDecompressGzipToStrNull() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnResponseHeaderBufferBuffer() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnExceptionThrowable() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnExceptionThrowableWithCallback() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnConnectionFailedThrowable() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testOnConnectionFailedThrowableException() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testExpireHttpDestination() {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testExpireHttpDestinationException() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testIsGzip() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetResponse() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetResponseGzip() throws Exception {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
+import org.junit.runner.RunWith;
import net.sf.json.JSONObject;
import mockit.Mock;
import mockit.MockUp;
+import mockit.integration.junit4.JMockit;
/**
* <br/>
* </p>
*
* @author
- * @version SDNO 0.5 20-Jun-2016
+ * @version 20-Jun-2016
*/
+@RunWith(JMockit.class)
public class TestRestfulConfigure {
/**
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
- *
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testRestfulConfigure() throws Exception {
final RestfulConfigure configure = new RestfulConfigure();
/**
* <br/>
- *
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testRestfulConfigureAppRootNull() throws Exception {
new MockUp<SystemEnvVariablesDefImpl>() {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testRestfulConfigureDefault() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testRestfulConfigureException() throws Exception {
}
/**
- * <br/>
*
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testRestfulConfigureString() {
final String configFile = "rest-client-test.json";
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public final void testGetOptions() {
}
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
import mockit.Mock;
import mockit.MockUp;
+import mockit.integration.junit4.JMockit;
/**
* <br/>
* </p>
*
* @author
- * @version SDNO 0.5 21-Jun-2016
+ * @version 21-Jun-2016
*/
+@RunWith(JMockit.class)
public class TestRestfulFactory {
/**
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRestInstance() {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 20-Jun-2016
+ * @version 20-Jun-2016
*/
@RunWith(JMockit.class)
public class TestRestfulOptions {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
- */
- @Test
- public void testSetCalledServiceName() {
- final RestfulOptions options = new RestfulOptions();
- final String serviceName = "sample-service";
- assertTrue(options.setCalledServiceName(serviceName));
- assertEquals(serviceName, options.getCalledServicName());
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
- */
- @Test
- public void testGetCalledServicName() {
- final RestfulOptions options = new RestfulOptions();
- final String serviceName = "sample-service";
- assertEquals("", options.getCalledServicName());
- options.setCalledServiceName(serviceName);
- assertEquals(serviceName, options.getCalledServicName());
- }
-
- /**
- * <br/>
- *
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetPort() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetPort() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetHost() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetHost() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetRestTimeout() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRestTimeout() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetOption() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetIntOption() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStringOption() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetOption() {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 21-Jun-2016
+ * @version 21-Jun-2016
*/
public class TestRestfulParametes {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGet() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetRawData() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRawData() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testPut() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testPutHttpContextHeaderStringString() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testPutHttpContextHeaderStringInt() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetHttpContextHeader() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetParamMap() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetParamMap() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetHeaderMap() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetHeaderMap() {
/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* </p>
*
* @author
- * @version SDNO 0.5 20-Jun-2016
+ * @version 20-Jun-2016
*/
public class TestRestfulResponse {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStatus() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetStatus() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRespHeaderMap() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetRespHeaderMap() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRespHeaderInt() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRespHeaderLong() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetRespHeaderStr() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetResponseContent() {
/**
* <br/>
*
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testSetResponseJson() {