У меня есть Клиент Отдыха для использования услуги soap. Теперь я написал свой код в рамках реализации JAX-WS с развертыванием через weblogi c 12 c. Но после развертывания, когда я нажимаю на URL, появляется 404. Я изменил свои web- xml и weblogi c. xml соответственно, но ничего не произошло.
Пожалуйста, помогите, где я делаю неправильно?
WebServiceClient. java
package com.fms.webservice.client;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Properties;
import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.log4j.Logger;
import org.glassfish.jersey.client.ClientConfig;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import com.fms.webservices.abl.stubs.FundsTransfer;
import com.fms.webservices.abl.stubs.FundsTransferReq;
import com.fms.webservices.abl.stubs.RequestHeader;
@Path("/fmsServices")
public class WebServiceClient {
/**Final Strings to hold the database configuarational values..*/
private static String JDBC_URL;
private static String JDBC_USER;
private static String JDBC_PASSWORD;
private static String JDBC_DRIVER_CLASS;
private static String JDBC_KEY;
private static String configFile;
private static WebServiceClient config;
private Properties properties = new Properties();
static String propFileName = "/config.properties";
private Logger logger = LogManager.getInstance().getRootLogger();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
private String authCode = "";
static {
config = null;
if (config == null) {
config = new WebServiceClient();
try {
config.init(propFileName);
} catch (Exception io) {
io.printStackTrace();
System.out.println("");
}
}
}
/**Static variables initialization for the parameters values provided in the config file.. */
private synchronized void init(String configFileName) throws Exception {
if (WebServiceClient.configFile == null) {
WebServiceClient.configFile = configFileName;
InputStream configFile = WebServiceClient.class.getResourceAsStream(configFileName);
properties.load(configFile);
JDBC_URL = properties.getProperty("JDBC_URL"); // Database URL..
JDBC_USER = properties.getProperty("JDBC_USER"); // Database USER..
JDBC_PASSWORD = properties.getProperty("JDBC_PASSWORD"); // Database Password..
JDBC_DRIVER_CLASS = properties.getProperty("JDBC_DRIVER_CLASS"); // Database Driver..
JDBC_KEY = properties.getProperty("JDBC_KEY"); // Encrypted Key for Password..
properties.getProperty("PROXY_SERVER_URL");
}
}
public static void webServiceCaller() throws IOException {
}
@GET
@Path("/fundTransfer")
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public String soapCaller() throws IOException, JSONException {
@SuppressWarnings({ "rawtypes", "unused" })
HashMap map = new HashMap<>();
try {
StringBuilder sb = new StringBuilder();
logger.info("soapCaller !!");
String urlParameters = "grant_type=client_credentials&client_id=0146b9a4-7e99-4c83-8e9e-6049cfec55da&client_secret=nY3oL5xQ3bJ8yT3nC1nV5bY4mY6eW7yP1nY6dS6rQ2nE5iR0rM&scope=ABLApis";
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
URL url = new URL("https://221.120.211.69:443/abl-api/uat/oauth2/token");// your url i.e fetch data from .
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("accept", "application/json");
conn.setRequestProperty("charset", "utf-8");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
conn.setUseCaches(false);
try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
wr.write(postData);
}
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
}
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(in);
String output;
while ((output = br.readLine()) != null) {
String[] list = output.split(",");
for (int i = 0; i < list.length; i++)
sb.append(list[i]+ ",");
}
String singleString = sb.toString();
String[] entries = singleString.split(",");
JSONObject obj = new JSONObject("{"+ entries[1] + "}");
authCode = obj.get("access_token").toString();
conn.disconnect();
} catch (Exception e) {
System.out.println("Exception in UnitTests:- " + e);
}
final String API_URI = "https://221.120.211.69:443/abl-api/uat/ApiConnectFTwsdlDefinitionHttpService";
final ClientConfig config = new ClientConfig();
final Client client = ClientBuilder.newClient( new ClientConfig().register( WebServiceClient.class ) );
javax.ws.rs.core.MultivaluedHashMap<String, String> queryParams = new javax.ws.rs.core.MultivaluedHashMap();
queryParams.add("SystemName", "CDC");
queryParams.add("RequestID", "222");
queryParams.add("TenantID", "abc11323===+");
queryParams.add("CreditAccount", "0010000108290010");
queryParams.add("DebitAmount", "100");
queryParams.add("MappingID", "Remarks");
queryParams.add("Narration", "remarks");
WebTarget webResource = client.target(API_URI);
//WebResource webResource = client.resource(API_URI);
JSONObject requestObj = new JSONObject();
requestObj.put("SystemName", "CDC");
requestObj.put("RequestID", "222");
requestObj.put("TenantID", "abc11323===+");
requestObj.put("CreditAccount", "0010000108290010");
requestObj.put("DebitAmount", "100");
requestObj.put("MappingID", "Remarks");
requestObj.put("Narration", "remarks");
FundsTransferReq entity = new FundsTransferReq();
entity.setCreditAccount("0010000108290010");
entity.setDebitAmount("100");
entity.setMappingID("Remarks");
entity.setNarration("remakrks");
RequestHeader header = new RequestHeader();
FundsTransfer request = new FundsTransfer();
header.setRequestID(new BigInteger("222"));
header.setSystemName("cdc");
header.setTenantID("abc11323===+");
request.setRequestHeader(header);
request.setRequestBody(entity);
Response responseMsg = webResource.request()
.header("content-type", "application/json; charset=utf-8")
.header("SOAPAction", "http://ApiConnectFTwsdlDefinition/FundsTransfer")
.header("X-IBM-Client-Id", "0146b9a4-7e99-4c83-8e9e-6049cfec55da")
.header("Authorization", "Bearer "+ authCode)
.accept("application/json; charset=utf-8")
.post(Entity.entity(entity, MediaType.APPLICATION_XML));
System.out.println("Response Code >>> " + responseMsg.getStatus());
int PRETTY_PRINT_INDENT_FACTOR = 4;
JSONObject xmlJSONObj = XML.toJSONObject(responseMsg.readEntity(String.class));
String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
System.out.println(jsonPrettyPrintString);
return jsonPrettyPrintString;
}
/* public static void main(String[] args) throws IOException, JSONException {
String host = "172.18.101.2";
String port = "80";
System.out.println("Using proxy: " + host + ":" + port);
System.setProperty("https.proxyHost", host);
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);
System.setProperty("https.proxyPort", port);
SSLUtilities.trustAllHostnames();
SSLUtilities.trustAllHttpsCertificates();
webServiceCaller();
soapCaller();
}*/
}
web. xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-XMLExample-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.fms.webservice.client</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-XMLExample-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
weblogi c. xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">
<wls:weblogic-version>12.2.1.2</wls:weblogic-version>
<wls:context-root>FMS_WEB_SERVICES</wls:context-root>
</wls:weblogic-web-app>
URL, который я пробую http://localhost: 7002 / FMS_WEB_SERVICES / fmsServices / fundTransfer