Monday, 11 June 2018

Java Helper class to invoke SOAP web service using proxy in Oracle ADF

Following is the code snippet can be used as a helper class to invoke SOAP web service via proxy in Oracle ADF



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import com.oracle.xmlns.apps.xxsrf.soaprovider.plsql.xxsrf_capex_api.XXSRF_CAPEX_API_PortType;
import com.oracle.xmlns.apps.xxsrf.soaprovider.plsql.xxsrf_capex_api.XXSRF_CAPEX_API_Service;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import oracle.adf.share.logging.ADFLogger;
import oracle.wsm.security.util.SecurityConstants;
import weblogic.wsee.jws.jaxws.owsm.SecurityPoliciesFeature;


public class WebserviceHelper {
  private static final ADFLogger LOGGER = ADFLogger.createADFLogger(WebserviceHelper.class);

  public WebserviceHelper() {
    super();
  }

  // Creating instance of Service.java class
  private static XXSRF_CAPEX_API_Service xXSRF_CAPEX_API_Service;
  private static InputStream input = null;
  private static Properties prop = new Properties();

  public XXSRF_CAPEX_API_PortType getWsPort() {
    String url = null;
    URL urlObj;
    try {
      input = new FileInputStream("/app/scripts/SRFConfig.properties");
      prop.load(input);
      url = prop.getProperty("CAPEX_APPROVAL_URL");
      LOGGER.info("WSDL URL " + url);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      urlObj = new URL(url);
      QName qName =
          new QName("http://xmlns.oracle.com/apps/xxsrf/soaprovider/plsql/xxsrf_capex_api/",
              "XXSRF_CAPEX_API_Service");

      LOGGER.info("WSDL URL Object " + urlObj);
      LOGGER.info("qName " + qName);
      xXSRF_CAPEX_API_Service = new XXSRF_CAPEX_API_Service(urlObj, qName);
      SecurityPoliciesFeature securityFeatures =
          new SecurityPoliciesFeature(new String[] {"oracle/wss_username_token_client_policy"});
      XXSRF_CAPEX_API_PortType xXSRF_CAPEX_API_PortType =
          xXSRF_CAPEX_API_Service.getXXSRF_CAPEX_API_Port(securityFeatures);
      // Add your code to call the desired methods.
      BindingProvider bindingProvider = (BindingProvider) xXSRF_CAPEX_API_PortType;
      Map<String, Object> context = bindingProvider.getRequestContext();
      // context.put(WSBindingProvider.USERNAME_PROPERTY, "Test");
      // context.put(WSBindingProvider.PASSWORD_PROPERTY, "Test");
      context.put(SecurityConstants.ClientConstants.WSS_CSF_KEY, "user-key");
      // bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
      return xXSRF_CAPEX_API_PortType;
    } catch (MalformedURLException e) {
      LOGGER.info("Inside the catch block" + e);
      e.printStackTrace();
    }
    return null;
  }
}

No comments:

Post a Comment