org.apache.cxf.feature.LoggingFeature Java Examples

The following examples show how to use org.apache.cxf.feature.LoggingFeature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoviesTest.java    From microservice-with-jwt-and-microprofile with Apache License 2.0 6 votes vote down vote up
@Test
public void sthg() throws Exception {

    final WebClient webClient = WebClient
            .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()), singletonList(new LoggingFeature()), null);

    webClient
            .reset()
            .path("/rest/greeting/")
            .get(String.class);

    final Collection<? extends Movie> movies = webClient
            .reset()
            .path("/rest/movies/")
            .header("Authorization", "Bearer " + token())
            .getCollection(Movie.class);

    System.out.println(movies);
}
 
Example #2
Source File: JaxwsClientToCxfServerIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setup() {
	final Bus bus = CXFBusFactory.getThreadDefaultBus();

	JaxWsServerFactoryBean jaxWsServer = createJaxWsServer();
	jaxWsServer.getFeatures().add(new LoggingFeature());
	jaxWsServer.getFeatures().add(new TraceeCxfFeature(serverBackend, Profile.DEFAULT));
	server = jaxWsServer.create();

	JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();

	factoryBean.setServiceClass(HelloWorldTestService.class);
	factoryBean.setAddress(endpointAddress);
	factoryBean.getHandlers().add(new TraceeClientHandler(clientBackend));
	factoryBean.setBus(bus);

	helloWorldPort = factoryBean.create(HelloWorldTestService.class);
}
 
Example #3
Source File: SoapCollectorTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setPrettyLogging(true);
    factory.getFeatures().add(loggingFeature);

    TestServiceImpl testService = new TestServiceImpl();
    factory.setServiceBean(testService);
    factory.setAddress("http://localhost:9090/test");
    cxfServer = factory.create();
    cxfServer.start();

    while (!cxfServer.isStarted()) {
        Thread.sleep(200);
    }
}
 
Example #4
Source File: RestOrderApplication.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Override
public Set<Object> getSingletons() {
    Swagger2Feature swagger = new Swagger2Feature();
    swagger.setBasePath("/");
    swagger.setHost("localhost:9000");
    swagger.setTitle("Order Service");
    swagger.setDescription("Rider Auto Parts Order Service");
    swagger.setVersion("2.0.0");
    swagger.setContact("[email protected]");
    swagger.setPrettyPrint(true);

    Set<Object> answer = new HashSet<>();
    answer.add(orderService);
    answer.add(new JacksonJsonProvider());
    answer.add(swagger);
    // to turn on verbose logging
    answer.add(new LoggingFeature());
    return answer;
}
 
Example #5
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 6 votes vote down vote up
private static void createServerEndpoint() {
  JaxWsServerFactoryBean jaxWsServerFactoryBean =
      new JaxWsServerFactoryBean();

  // create the loggingFeature
  LoggingFeature loggingFeature = new LoggingFeature();
  loggingFeature.setPrettyLogging(true);

  // add the loggingFeature to print the received/sent messages
  jaxWsServerFactoryBean.getFeatures().add(loggingFeature);

  HelloWorldImpl implementor = new HelloWorldImpl();
  jaxWsServerFactoryBean.setServiceBean(implementor);
  jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS);

  jaxWsServerFactoryBean.create();
}
 
Example #6
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // start the HelloWorld service using jaxWsServerFactoryBean
  JaxWsServerFactoryBean jaxWsServerFactoryBean =
      new JaxWsServerFactoryBean();

  // adding loggingFeature to print the received/sent messages
  LoggingFeature loggingFeature = new LoggingFeature();
  loggingFeature.setPrettyLogging(true);

  jaxWsServerFactoryBean.getFeatures().add(loggingFeature);

  // setting the implementation
  HelloWorldImpl implementor = new HelloWorldImpl();
  jaxWsServerFactoryBean.setServiceBean(implementor);
  // setting the endpoint
  jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS);
  jaxWsServerFactoryBean.create();
}
 
Example #7
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // start the HelloWorld service using jaxWsServerFactoryBean
  JaxWsServerFactoryBean jaxWsServerFactoryBean =
      new JaxWsServerFactoryBean();

  // adding loggingFeature to print the received/sent messages
  LoggingFeature loggingFeature = new LoggingFeature();
  loggingFeature.setPrettyLogging(true);

  jaxWsServerFactoryBean.getFeatures().add(loggingFeature);

  // setting the implementation
  HelloWorldImpl implementor = new HelloWorldImpl();
  jaxWsServerFactoryBean.setServiceBean(implementor);
  // setting the endpoint
  jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS);
  jaxWsServerFactoryBean.create();
}
 
Example #8
Source File: AmbariClientBuilder.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Build a client proxy, for a specific proxy type.
 * 
 * @param proxyType proxy type class
 * @return client proxy stub
 */
protected <T> T build(Class<T> proxyType) {
    String address = generateAddress();
    T rootResource;
    // Synchronized on the class to correlate with the scope of clientStaticResources
    // We want to ensure that the shared bean isn't set concurrently in multiple callers
    synchronized (AmbariClientBuilder.class) {
        JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
        bean.setAddress(address);
        if (username != null) {
            bean.setUsername(username);
            bean.setPassword(password);
        }

        if (enableLogging) {
            bean.setFeatures(Arrays.<AbstractFeature> asList(new LoggingFeature()));
        }
        rootResource = bean.create(proxyType);
    }

    boolean isTlsEnabled = address.startsWith("https://");
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
        TLSClientParameters tlsParams = new TLSClientParameters();
        if (!validateCerts) {
            tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
        } else if (trustManagers != null) {
            tlsParams.setTrustManagers(trustManagers);
        }
        tlsParams.setDisableCNCheck(!validateCn);
        conduit.setTlsClientParameters(tlsParams);
    }

    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
}
 
Example #9
Source File: CxfClientToJaxwsServerIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
	JaxWsServerFactoryBean jaxWsServer = createJaxWsServer();
	jaxWsServer.getHandlers().add(new TraceeClientHandler(serverBackend));
	server = jaxWsServer.create();

	final ClientProxyFactoryBean factoryBean = new ClientProxyFactoryBean();
	factoryBean.getFeatures().add(new LoggingFeature());
	factoryBean.getFeatures().add(new TraceeCxfFeature(clientBackend, Profile.DEFAULT));
	factoryBean.setServiceClass(HelloWorldTestService.class);
	factoryBean.setAddress(endpointAddress);
	helloWorldPort = (HelloWorldTestService) factoryBean.create();
}
 
Example #10
Source File: CxfClientToCxfServerIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
	JaxWsServerFactoryBean jaxWsServer = createJaxWsServer();
	jaxWsServer.getFeatures().add(new LoggingFeature());
	jaxWsServer.getFeatures().add(new TraceeCxfFeature(serverBackend, Profile.DEFAULT));
	server = jaxWsServer.create();

	final ClientProxyFactoryBean factoryBean = new ClientProxyFactoryBean();
	factoryBean.getFeatures().add(new LoggingFeature());
	factoryBean.getFeatures().add(new TraceeCxfFeature(clientBackend, Profile.DEFAULT));
	factoryBean.setServiceClass(HelloWorldTestService.class);
	factoryBean.setBus(CXFBusFactory.getDefaultBus());
	factoryBean.setAddress(endpointAddress);
	helloWorldPort = (HelloWorldTestService) factoryBean.create();
}
 
Example #11
Source File: GlobalFeatureConfigTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Configuration
public Properties p() {
    return new Properties() {{
        setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");

        setProperty(CxfUtil.BUS_PREFIX + CxfUtil.FEATURES, "logging");
        setProperty("logging", "new://Service?class-name=" + LoggingFeature.class.getName());
    }};
}
 
Example #12
Source File: ShaHashSizesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #13
Source File: InvalidSignatureTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #14
Source File: RsaKeySizesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #15
Source File: MinimumRequiredClaimsTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #16
Source File: MissingRequiredClaimsTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #17
Source File: GlobalFeatureConfigTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void run() {
    final Bus bus = CxfUtil.getBus();
    assertEquals(1, bus.getFeatures().size());
    assertThat(bus.getFeatures().iterator().next(), instanceOf(LoggingFeature.class));
}
 
Example #18
Source File: MovieServiceTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #19
Source File: BookstoreTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void movieRestTest() throws Exception {
    final WebClient webClient = WebClient
            .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
                    singletonList(new LoggingFeature()), null);


    // Testing REST endpoint that returns the value of a JWT claim
    String responsePayload = webClient.reset()
            .path("/rest/bookstore/me")
            .header("Authorization", "Bearer " + token(true))
            .get(String.class);
    LOGGER.info("responsePayload = " + responsePayload);
    assertEquals("alice", responsePayload);


    // Testing REST endpoint with group claims manager
    Book newBook = new Book(1, "The Lord of the Rings", "J.R.R.Tolkien");
    Response response = webClient.reset()
            .path("/rest/bookstore")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + token(true))
            .post(newBook);
    LOGGER.info("responseCode = " + response.getStatus());
    assertEquals(204, response.getStatus());

    // Testing REST endpoint with group claims reader
    Collection<? extends Book> books = webClient
            .reset()
            .path("/rest/bookstore")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + token(false))
            .getCollection(Book.class);
    LOGGER.info(books.toString());
    assertEquals(1, books.size());


    // Should return a 403 since POST requires group claim manager but provided token has only reader.
    Book secondBook = new Book(2, "Mistborn: The Final Empire", "Brandon Sanderson");
    Response responseWithError = webClient.reset()
            .path("/rest/bookstore")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + token(false))
            .post(secondBook);
    LOGGER.info("responseCode = " + responseWithError.getStatus());
    assertEquals(403, responseWithError.getStatus());


    // Should return a 401 since the POST request lacks the Authorization header
    Response responseWith401Error = webClient.reset()
            .path("/rest/bookstore")
            .header("Content-Type", "application/json")
            .post(new Book());
    LOGGER.info("responseCode = " + responseWith401Error.getStatus());
    assertEquals(401, responseWith401Error.getStatus());
}
 
Example #20
Source File: MoviesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
public void movieRestTest() throws Exception {

    final WebClient webClient = WebClient
            .create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
                    singletonList(new LoggingFeature()), null);


    //Testing rest endpoint deployment (GET  without security header)
    String responsePayload = webClient.reset().path("/rest/cinema/").get(String.class);
    LOGGER.info("responsePayload = " + responsePayload);
    assertTrue(responsePayload.equalsIgnoreCase("ok"));


    //POST (Using token1.json with group of claims: [CRUD])
    Movie newMovie = new Movie(1, "David Dobkin", "Wedding Crashers");
    Response response = webClient.reset()
                                 .path("/rest/cinema/movies")
                                 .header("Content-Type", "application/json")
                                 .header("Authorization", "Bearer " + token(1))
                                 .post(newMovie);
    LOGGER.info("responseCode = " + response.getStatus());
    assertTrue(response.getStatus() == 204);


    //GET movies (Using token2.json with group of claims: [read-only])
    Collection<? extends Movie> movies = webClient
            .reset()
            .path("/rest/cinema/movies")
            .header("Content-Type", "application/json")
            .header("Authorization", "Bearer " + token(2))
            .getCollection(Movie.class);
    LOGGER.info(movies.toString());
    assertTrue(movies.size() == 1);


    //Should return a 403 since POST require group of claims: [crud] but Token 2 has only [read-only].
    Movie secondNewMovie = new Movie(2, "Todd Phillips", "Starsky & Hutch");
    Response responseWithError = webClient.reset()
                                          .path("/rest/cinema/movies")
                                          .header("Content-Type", "application/json")
                                          .header("Authorization", "Bearer " + token(2))
                                          .post(secondNewMovie);
    LOGGER.info("responseCode = " + responseWithError.getStatus());
    assertTrue(responseWithError.getStatus() == 403);


    //Should return a 401 since the header Authorization is not part of the POST request.
    Response responseWith401Error = webClient.reset()
                                             .path("/rest/cinema/movies")
                                             .header("Content-Type", "application/json")
                                             .post(new Movie());
    LOGGER.info("responseCode = " + responseWith401Error.getStatus());
    assertTrue(responseWith401Error.getStatus() == 401);

}
 
Example #21
Source File: MovieServiceTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static WebClient createWebClient(final URL base) {
    return WebClient.create(base.toExternalForm(), singletonList(new JohnzonProvider<>()),
            singletonList(new LoggingFeature()), null);
}
 
Example #22
Source File: FHIRClientImpl.java    From FHIR with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves a jax-rs Client from the ClientBuilder object. The Client instance is created if necessary.
 */
protected synchronized Client getClient() throws Exception {
    if (client == null) {
        ClientBuilder cb = ClientBuilder.newBuilder()
                .register(new FHIRProvider(RuntimeType.CLIENT))
                .register(new FHIRJsonProvider(RuntimeType.CLIENT))
                .register(new FHIRJsonPatchProvider(RuntimeType.CLIENT));

        // Add support for basic auth if enabled.
        if (isBasicAuthEnabled()) {
            cb = cb.register(new FHIRBasicAuthenticator(getBasicAuthUsername(), getBasicAuthPassword()));
        }

        // Add support for OAuth 2.0 if enabled.
        if (isOAuth2Enabled()) {
            cb = cb.register(new FHIROAuth2Authenticator(getOAuth2AccessToken()));
        }

        // If using oAuth 2.0 or clientauth, then we need to attach our Keystore.
        if (isOAuth2Enabled() || isClientAuthEnabled()) {
            cb = cb.keyStore(getKeyStore(), getKeyStoreKeyPassword());
        }

        // If using oAuth 2.0 or clientauth or an https endpoint, then we need to attach our Truststore.
        KeyStore ks = getTrustStore();
        if (ks != null) {
            cb = cb.trustStore(ks);
        }

        // Add a hostname verifier if we're using an ssl transport.
        if (usingSSLTransport() && !isHostnameVerificationEnabled()) {
            cb = cb.hostnameVerifier(new HostnameVerifier() {

                @Override
                public boolean verify(String s, SSLSession sslSession) {
                    return true;
                }
            });
        }

        // Set the http client's receive timeout setting
        cb.property("http.receive.timeout", getHttpTimeout()); // defaults to 60s

        // true: If need, tell Apache CXF to use the Async HTTP conduit for PATCH operation as the
        // default HTTP conduit does not support PATCH
        // false(default): To avoid the http async client time out issue (http://mail-archives.apache.org
        // /mod_mbox/hc-dev/201909.mbox/%[email protected]%3E),
        // please set this to false.
        cb.property("use.async.http.conduit", false);

        // Add request/response logging if enabled.
        if (isLoggingEnabled()) {
            cb.register(LoggingFeature.class);
        }

        // Save off our cached Client instance.
        client = cb.build();
    }
    return client;
}
 
Example #23
Source File: NetSuiteClientServiceImpl.java    From components with Apache License 2.0 4 votes vote down vote up
@Override
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2019.2/netsuite.wsdl");

        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);

        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(
                features.toArray(new WebServiceFeature[features.size()]));

        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);

        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain",
                            defaultEndpointUrl));
        }

        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());

        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, !isUseRequestLevelCredentials());
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

        return port;
    } catch (WebServiceException | MalformedURLException |
            InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault |
            UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient",
                        e.getLocalizedMessage()), e);
    }
}
 
Example #24
Source File: NetSuiteClientServiceImpl.java    From components with Apache License 2.0 4 votes vote down vote up
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2014.2/netsuite.wsdl");

        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);

        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(
                features.toArray(new WebServiceFeature[features.size()]));

        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);

        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain",
                            defaultEndpointUrl));
        }

        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());

        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, !isUseRequestLevelCredentials());
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

        return port;
    } catch (WebServiceException | MalformedURLException |
            UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient",
                        e.getLocalizedMessage()), e);
    }
}
 
Example #25
Source File: NetSuiteClientServiceImpl.java    From components with Apache License 2.0 4 votes vote down vote up
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2018.2/netsuite.wsdl");

        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);

        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(
                features.toArray(new WebServiceFeature[features.size()]));

        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);

        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain",
                            defaultEndpointUrl));
        }

        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());

        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, !isUseRequestLevelCredentials());
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

        return port;
    } catch (WebServiceException | MalformedURLException |
            InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault |
            UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient",
                        e.getLocalizedMessage()), e);
    }
}
 
Example #26
Source File: NetSuiteClientServiceImpl.java    From components with Apache License 2.0 4 votes vote down vote up
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2016.2/netsuite.wsdl");

        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);

        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(
                features.toArray(new WebServiceFeature[features.size()]));

        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);

        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain",
                            defaultEndpointUrl));
        }

        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());

        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, !isUseRequestLevelCredentials());
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

        return port;
    } catch (WebServiceException | MalformedURLException |
            InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault |
            UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient",
                        e.getLocalizedMessage()), e);
    }
}
 
Example #27
Source File: WebServicesConfiguration.java    From microservices-transactions-tcc with Apache License 2.0 4 votes vote down vote up
@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new ExceptionRestHandler()));
    
    Map<Object, Object> mappings = new HashMap<Object, Object>();
    mappings.put("json", "application/json");
    endpoint.setExtensionMappings(mappings);
    
    Swagger2Feature swagger2Feature = new Swagger2Feature();
    swagger2Feature.setTitle(title);
    swagger2Feature.setDescription(description);
    swagger2Feature.setVersion(version);
    swagger2Feature.setContact(contact);
    swagger2Feature.setSchemes(schemes.split(","));
    swagger2Feature.setBasePath(basePath);
    swagger2Feature.setResourcePackage(resourcePackage);
    swagger2Feature.setPrettyPrint(prettyPrint);
    swagger2Feature.setScan(scan);
    
    endpoint.setFeatures(Arrays.asList(new LoggingFeature(), swagger2Feature));
    endpoint.setServiceBeans(Arrays.asList(tccCoordinatorService, compositeController));
    
    return endpoint.create();
}