Java Code Examples for javax.xml.ws.BindingProvider#getRequestContext()

The following examples show how to use javax.xml.ws.BindingProvider#getRequestContext() . 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: WSAFromJavaTest.java    From cxf with Apache License 2.0 9 votes vote down vote up
@Test
public void testAddNumbersJaxWsContext() throws Exception {
    ByteArrayOutputStream output = setupOutLogging();

    AddNumberImpl port = getPort();

    BindingProvider bp = (BindingProvider)port;
    java.util.Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "cxf");

    try {
        assertEquals(3, port.addNumbers(1, 2));
        fail("Should have thrown an ActionNotSupported exception");
    } catch (SOAPFaultException ex) {
        //expected
    }
    assertLogContains(output.toString(), "//wsa:Action", "cxf");
    assertTrue(output.toString(), output.toString().indexOf("SOAPAction=\"cxf\"") != -1);
}
 
Example 2
Source File: WebServiceTools.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets the timeout for this web service client. Every port created by a JAX-WS can be cast to
 * BindingProvider.
 */
public static void setTimeout(BindingProvider port, int timeout) {
	if (port == null) {
		throw new IllegalArgumentException("port must not be null!");
	}

	Map<String, Object> ctxt = port.getRequestContext();
	ctxt.put("com.sun.xml.ws.developer.JAXWSProperties.CONNECT_TIMEOUT", timeout);
	ctxt.put("com.sun.xml.ws.connect.timeout", timeout);
	ctxt.put("com.sun.xml.ws.request.timeout", timeout);
	ctxt.put("com.sun.xml.internal.ws.connect.timeout", timeout);
	ctxt.put("com.sun.xml.internal.ws.request.timeout", timeout);

	// We don't want to use proprietary Sun code
	// ctxt.put(BindingProviderProperties.REQUEST_TIMEOUT, timeout);
	// ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, timeout);
}
 
Example 3
Source File: BesDAO.java    From development with Apache License 2.0 6 votes vote down vote up
public <T> void setEndpointInContext(BindingProvider client,
        Map<String, Setting> settings, Class<T> serviceClass) {
    Map<String, Object> clientRequestContext = client.getRequestContext();
    String wsUrl = "";
    if (isSsoMode(settings)) {
        wsUrl = settings.get(
                PlatformConfigurationKey.BSS_STS_WEBSERVICE_URL.name())
                .getValue();
    } else {
        wsUrl = settings.get(
                PlatformConfigurationKey.BSS_WEBSERVICE_URL.name())
                .getValue();
    }
    wsUrl = wsUrl.replace("{SERVICE}", serviceClass.getSimpleName());
    clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            wsUrl);
}
 
Example 4
Source File: SOAPJMSTestSuiteTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void oneWayTest(TestCaseType testcase, JMSSimplePortType port) throws Exception {
    closeable = (java.io.Closeable)port;
    InvocationHandler handler = Proxy.getInvocationHandler(port);
    BindingProvider bp = (BindingProvider)handler;

    Map<String, Object> requestContext = bp.getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();

    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    Exception e = null;
    try {
        port.ping("test");
    } catch (Exception e1) {
        e = e1;
    }
    checkJMSProperties(testcase, requestHeader);
    if (e != null) {
        throw e;
    }
}
 
Example 5
Source File: JMSSharedQueueTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void callGreetMe() {
    BindingProvider bp = (BindingProvider)port;
    Map<String, Object> requestContext = bp.getRequestContext();
    JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    String request = "World" + ((prefix != null) ? ":" + prefix : "");
    String correlationID = null;
    if (corrFactory != null) {
        correlationID = corrFactory.createCorrealtionID();
        requestHeader.setJMSCorrelationID(correlationID);
        request +=  ":" + correlationID;
    }
    String expected = "Hello " + request;
    String response = port.greetMe(request);
    Assert.assertEquals("Response didn't match expected request", expected, response);
    if (corrFactory != null) {
        Map<String, Object> responseContext = bp.getResponseContext();
        JMSMessageHeadersType responseHeader =
            (JMSMessageHeadersType)responseContext.get(
                    JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
        Assert.assertEquals("Request and Response CorrelationID didn't match",
                      correlationID, responseHeader.getJMSCorrelationID());
    }
}
 
Example 6
Source File: WSAFaultToClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneWayFaultTo() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPServiceAddressing");

    Greeter greeter = new SOAPService(wsdl, serviceName).getPort(Greeter.class, new AddressingFeature());
    EndpointReferenceType faultTo = new EndpointReferenceType();
    AddressingProperties addrProperties = new AddressingProperties();
    AttributedURIType epr = new AttributedURIType();
    String faultToAddress = "http://localhost:" + FaultToEndpointServer.FAULT_PORT  + "/faultTo";
    epr.setValue(faultToAddress);
    faultTo.setAddress(epr);
    addrProperties.setFaultTo(faultTo);

    BindingProvider provider = (BindingProvider) greeter;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                       "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/greeter");
    requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);

    greeter.greetMeOneWay("test");
    //wait for the fault request
    int i = 2;
    while (HelloHandler.getFaultRequestPath() == null && i > 0) {
        Thread.sleep(500);
        i--;
    }
    assertTrue("FaultTo request fpath isn't expected",
               "/faultTo".equals(HelloHandler.getFaultRequestPath()));
}
 
Example 7
Source File: NaiveSSLHelper.java    From onvif with Apache License 2.0 5 votes vote down vote up
public static void makeWebServiceClientTrustEveryone(Object webServicePort) {
  if (webServicePort instanceof BindingProvider) {
    BindingProvider bp = (BindingProvider) webServicePort;
    Map requestContext = bp.getRequestContext();
    requestContext.put(JAXWS_SSL_SOCKET_FACTORY, getTrustingSSLSocketFactory());
    requestContext.put(JAXWS_HOSTNAME_VERIFIER, new NaiveHostnameVerifier());
  } else {
    throw new IllegalArgumentException(
        "Web service port "
            + webServicePort.getClass().getName()
            + " does not implement "
            + BindingProvider.class.getName());
  }
}
 
Example 8
Source File: WSAFromJavaTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnmatchedActions() throws Exception {
    AddNumberImpl port = getPort();

    BindingProvider bp = (BindingProvider)port;
    java.util.Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY,
                       "http://cxf.apache.org/input4");
    try {
        //CXF-2035
        port.addNumbers3(-1, -1);
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Unexpected wrapper"));
    }
}
 
Example 9
Source File: NetSuiteClientService.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a SOAP header from header list to be sent to NetSuite
 *
 * @param port port
 * @param name name identifying a header
 */
protected void removeHeader(PortT port, QName name) {
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    removeHeader(list, name);
}
 
Example 10
Source File: NetSuiteClientService.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * Set a SOAP header to be sent to NetSuite in request
 *
 * @param port port
 * @param header header to be set
 */
protected void setHeader(PortT port, Header header) {
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    if (list == null) {
        list = new ArrayList<>();
        requestContext.put(Header.HEADER_LIST, list);
    }
    removeHeader(list, header.getName());
    list.add(header);
}
 
Example 11
Source File: SOAPJMSTestSuiteTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void twoWayTestWithRequestHeader(TestCaseType testcase, final JMSSimplePortType port,
                                         JMSMessageHeadersType requestHeader)
    throws Exception {
    closeable = (java.io.Closeable)port;
    InvocationHandler handler = Proxy.getInvocationHandler(port);
    BindingProvider bp = (BindingProvider)handler;

    Map<String, Object> requestContext = bp.getRequestContext();
    if (requestHeader == null) {
        requestHeader = new JMSMessageHeadersType();
    }
    requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
    Exception e = null;
    try {
        String response = port.echo("test");
        assertEquals(response, "test");
    } catch (WebServiceException ew) {
        throw ew;
    } catch (Exception e1) {
        e = e1;
    }
    Map<String, Object> responseContext = bp.getResponseContext();
    JMSMessageHeadersType responseHeader = (JMSMessageHeadersType)responseContext
        .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    checkJMSProperties(testcase, requestHeader, responseHeader);
    if (e != null) {
        throw e;
    }
}
 
Example 12
Source File: ServiceFactory.java    From development with Apache License 2.0 5 votes vote down vote up
public <T> T getBESWebService(Class<T> serviceClass)
        throws ParserConfigurationException {
    T client = getServicePort(serviceClass);
    BindingProvider bindingProvider = (BindingProvider) client;
    Map<String, Object> clientRequestContext = bindingProvider
            .getRequestContext();
    clientRequestContext.put(BindingProvider.USERNAME_PROPERTY, userName);
    clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
    return client;
}
 
Example 13
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 14
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 15
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 16
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 17
Source File: WSClientConfig.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@OverrideOnDemand
@OverridingMethodsMustInvokeSuper
public void applyWSSettingsToBindingProvider (@Nonnull final BindingProvider aBP)
{
  final Map <String, Object> aRequestContext = aBP.getRequestContext ();

  if (m_aEndpointAddress != null)
  {
    aRequestContext.put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, m_aEndpointAddress.toExternalForm ());
  }
  if (m_aSSLSocketFactory != null)
  {
    aRequestContext.put ("com.sun.xml.ws.transport.https.client.SSLSocketFactory", m_aSSLSocketFactory);
    aRequestContext.put ("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", m_aSSLSocketFactory);
  }
  if (m_aHostnameVerifier != null)
  {
    aRequestContext.put ("com.sun.xml.ws.transport.https.client.hostname.verifier", m_aHostnameVerifier);
    aRequestContext.put ("com.sun.xml.internal.ws.transport.https.client.hostname.verifier", m_aHostnameVerifier);
  }
  if (hasConnectionTimeoutMS ())
  {
    aRequestContext.put ("com.sun.xml.ws.connect.timeout", Integer.valueOf (m_nConnectionTimeoutMS));
    aRequestContext.put ("com.sun.xml.internal.ws.connect.timeout", Integer.valueOf (m_nConnectionTimeoutMS));
  }
  if (hasRequestTimeoutMS ())
  {
    aRequestContext.put ("com.sun.xml.ws.request.timeout", Integer.valueOf (m_nRequestTimeoutMS));
    aRequestContext.put ("com.sun.xml.internal.ws.request.timeout", Integer.valueOf (m_nRequestTimeoutMS));
  }
  if (hasChunkSize ())
  {
    aRequestContext.put ("com.sun.xml.ws.transport.http.client.streaming.chunk.size", Integer.valueOf (m_nChunkSize));
    aRequestContext.put ("com.sun.xml.internal.ws.transport.http.client.streaming.chunk.size",
                         Integer.valueOf (m_nChunkSize));
  }
  if (StringHelper.hasText (m_sUserName))
  {
    aRequestContext.put (BindingProvider.USERNAME_PROPERTY, m_sUserName);
    aRequestContext.put (BindingProvider.PASSWORD_PROPERTY, m_sPassword);
  }
  if (hasSOAPAction ())
  {
    aRequestContext.put (BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    aRequestContext.put (BindingProvider.SOAPACTION_URI_PROPERTY, m_sSOAPAction);
  }
  if (CollectionHelper.isNotEmpty (m_aHTTPHeaders))
  {
    aRequestContext.put (MessageContext.HTTP_REQUEST_HEADERS, m_aHTTPHeaders);
  }
  if (m_eCookiesSupport.isDefined ())
  {
    aRequestContext.put (BindingProvider.SESSION_MAINTAIN_PROPERTY, m_eCookiesSupport.getAsBooleanObj ());
  }

  if (m_aHandlers.isNotEmpty ())
  {
    @SuppressWarnings ("rawtypes")
    final List <Handler> aHandlers = aBP.getBinding ().getHandlerChain ();
    aHandlers.addAll (m_aHandlers);
    aBP.getBinding ().setHandlerChain (aHandlers);
  }

  customizeRequestContext (aRequestContext);

  if (m_bWorkAroundMASM0003)
  {
    // Introduced with Java 1.8.0_31??
    // MASM0003: Default [ jaxws-tubes-default.xml ] configuration file was
    // not loaded
    final ClassLoader aContextClassLoader = ClassLoaderHelper.getContextClassLoader ();
    final ClassLoader aThisClassLoader = IPrivilegedAction.getClassLoader (getClass ()).invokeSafe ();
    if (aContextClassLoader == null)
    {
      LOGGER.info ("Manually setting thread context class loader to work around MASM0003 bug");
      ClassLoaderHelper.setContextClassLoader (aThisClassLoader);
    }
    else
    {
      if (!aContextClassLoader.equals (aThisClassLoader))
      {
        LOGGER.warn ("Manually overriding thread context class loader to work around MASM0003 bug");
        ClassLoaderHelper.setContextClassLoader (aThisClassLoader);
      }
    }
  }
}
 
Example 18
Source File: JMSClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueueDecoupledOneWaysConnection() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms",
                                  "HelloWorldQueueDecoupledOneWaysService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldQueueDecoupledOneWaysPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    String wsdl2 = "testutils/jms_test.wsdl".intern();
    wsdlStrings.add(wsdl2);
    broker.updateWsdl(getBus(), wsdl2);

    HelloWorldQueueDecoupledOneWaysService service =
        new HelloWorldQueueDecoupledOneWaysService(wsdl, serviceName);
    Endpoint requestEndpoint = null;
    Endpoint replyEndpoint = null;
    HelloWorldOneWayPort greeter = service.getPort(portName, HelloWorldOneWayPort.class);
    try {
        GreeterImplQueueDecoupledOneWays requestServant = new GreeterImplQueueDecoupledOneWays();
        requestEndpoint = Endpoint.publish(null, requestServant, new LoggingFeature());
        GreeterImplQueueDecoupledOneWaysDeferredReply replyServant =
            new GreeterImplQueueDecoupledOneWaysDeferredReply();
        replyEndpoint = Endpoint.publish(null, replyServant, new LoggingFeature());

        BindingProvider bp = (BindingProvider)greeter;
        Map<String, Object> requestContext = bp.getRequestContext();
        JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
        requestHeader.setJMSReplyTo("dynamicQueues/test.jmstransport.oneway.with.set.replyto.reply");
        requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
        String expectedRequest = "JMS:Queue:Request";
        greeter.greetMeOneWay(expectedRequest);
        String request = requestServant.ackRequestReceived(5000);
        if (request == null) {
            if (requestServant.getException() != null) {
                fail(requestServant.getException().getMessage());
            } else {
                fail("The oneway call didn't reach its intended endpoint");
            }
        }
        assertEquals(expectedRequest, request);
        requestServant.proceedWithReply();
        String expectedReply = requestServant.ackReplySent(5000);
        if (expectedReply == null) {
            if (requestServant.getException() != null) {
                fail(requestServant.getException().getMessage());
            } else {
                fail("The decoupled one-way reply was not sent");
            }
        }
        String reply = replyServant.ackRequest(5000);
        if (reply == null) {
            if (replyServant.getException() != null) {
                fail(replyServant.getException().getMessage());
            } else {
                fail("The decoupled one-way reply didn't reach its intended endpoint");
            }
        }
        assertEquals(expectedReply, reply);
    } catch (Exception ex) {
        throw ex;
    } finally {
        if (requestEndpoint != null) {
            requestEndpoint.stop();
        }
        if (replyEndpoint != null) {
            replyEndpoint.stop();
        }
        ((java.io.Closeable)greeter).close();
    }
}
 
Example 19
Source File: WebServiceProxy.java    From development with Apache License 2.0 4 votes vote down vote up
public static <T> T get(String baseUrl, final String versionWSDL,
        String versionHeader, String auth, String namespace,
        Class<T> remoteInterface, String userName, String password, String tenantId, String orgId)
        throws Exception {
    String wsdlUrl = baseUrl + "/oscm/" + versionWSDL + "/"
            + remoteInterface.getSimpleName() + "/" + auth + "?wsdl";
    
    if (tenantId != null) {
        wsdlUrl += "&" + TENANT_ID + "=" + tenantId;
    }
    
    URL url = new URL(wsdlUrl);
    QName qName = new QName(namespace, remoteInterface.getSimpleName());
    Service service = Service.create(url, qName);
    if ("v1.7".equals(versionWSDL) || "v1.8".equals(versionWSDL)) {
        service.setHandlerResolver(new HandlerResolver() {
            @SuppressWarnings("rawtypes")
            @Override
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlerList = new ArrayList<Handler>();
                handlerList.add(new VersionHandlerCtmg(versionWSDL));
                return handlerList;
            }
        });
    } else {
        ClientVersionHandler versionHandler = new ClientVersionHandler(
                versionHeader);
        service = versionHandler.addVersionInformationToClient(service);
    }
    T port = service.getPort(remoteInterface);
    BindingProvider bindingProvider = (BindingProvider) port;
    Map<String, Object> clientRequestContext = bindingProvider
            .getRequestContext();
    if ("STS".equals(auth)) {
        clientRequestContext.put(XWSSConstants.USERNAME_PROPERTY, userName);
        clientRequestContext.put(XWSSConstants.PASSWORD_PROPERTY, password);
        
        
        clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                baseUrl + "/" + remoteInterface.getSimpleName() + "/"
                        + auth);
        
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        
        if(tenantId!= null){
            headers.put(TENANT_ID, Collections.singletonList(tenantId)); 
        }
        
        if(orgId!= null){
            headers.put("organizationId", Collections.singletonList(orgId)); 
        }
        
        clientRequestContext.put(MessageContext.HTTP_REQUEST_HEADERS,
                headers);
        
    } else {
        clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,
                userName);
        clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,
                password);
        clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                baseUrl + "/" + remoteInterface.getSimpleName() + "/"
                        + auth);
    }
    return port;
}
 
Example 20
Source File: WSAFaultToClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testTwoWayFaultTo() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    AddNumbersPortType port = getTwoWayPort();

    //setup a real decoupled endpoint that will process the fault correctly
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(port).getConduit();
    c.getClient().setDecoupledEndpoint("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");

    EndpointReferenceType faultTo = new EndpointReferenceType();
    AddressingProperties addrProperties = new AddressingProperties();
    AttributedURIType epr = new AttributedURIType();
    epr.setValue("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
    faultTo.setAddress(epr);
    addrProperties.setFaultTo(faultTo);

    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                       "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/add");
    requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);

    try {
        port.addNumbers(-1, -2);
        fail("Exception is expected");
    } catch (Exception e) {
        //do nothing
    }

    String in = new String(input.toByteArray());
    //System.out.println(in);
    assertTrue("The response from faultTo endpoint is expected and actual response is " + in,
               in.indexOf("Address: http://localhost:" + FaultToEndpointServer.FAULT_PORT2
                                 + "/sendFaultHere") > -1);
    assertTrue("WS addressing header is expected",
               in.indexOf("http://www.w3.org/2005/08/addressing") > -1);
    assertTrue("Fault deatil is expected",
               in.indexOf("Negative numbers cant be added") > -1);

    ((Closeable)port).close();
}