javax.xml.ws.BindingProvider Java Examples

The following examples show how to use javax.xml.ws.BindingProvider. 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: JMSSoapActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSayHi() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldServiceSoapAction");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);

    String response = new String("Bonjour");
    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);

    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingInInterceptor());

    ((BindingProvider)greeter).getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, "true");
    ((BindingProvider)greeter).getRequestContext().put(
        BindingProvider.SOAPACTION_URI_PROPERTY, "SAY_HI_1"
    );

    String reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);

    ((java.io.Closeable)greeter).close();
}
 
Example #2
Source File: JMSSoapActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSayHi2() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldServiceSoapAction");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    HelloWorldService service = new HelloWorldService(wsdl, serviceName);

    HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);

    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingInInterceptor());

    ((BindingProvider)greeter).getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, "true");
    ((BindingProvider)greeter).getRequestContext().put(
        BindingProvider.SOAPACTION_URI_PROPERTY, "SAY_HI_2"
    );

    try {
        greeter.sayHi();
        fail("Failure expected on spoofing attack");
    } catch (Exception ex) {
        // expected
    }
        
    ((java.io.Closeable)greeter).close();
}
 
Example #3
Source File: BesDAOTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void getUserDetails_givenUser_SSO() throws APPlatformException {
    // given
    besDAO.configService = confServ;
    Map<String, Setting> settings = getSettingsForMode("SAML_SP");
    doReturn(settings).when(besDAO.configService)
            .getAllProxyConfigurationSettings();
    doReturn(idServ).when(besDAO).getBESWebService(
            eq(IdentityService.class), any(ServiceInstance.class));
    VOUser user = givenUser(null, "mail");

    // when
    besDAO.getUserDetails(new ServiceInstance(), user, "password");

    // then
    verify(besDAO).setUserCredentialsInContext(any(BindingProvider.class),
            eq(user.getUserId()), eq("password"), eq(settings));
    verify(idServ).getCurrentUserDetails();
}
 
Example #4
Source File: WSADisableTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableAll() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    ByteArrayOutputStream output = setupOutLogging();

    AddNumbersPortType port = getService().getAddNumbersPort(new AddressingFeature(false));

    ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                    "http://localhost:"
                                                    + PORT + "/jaxws/add");

    assertEquals(3, port.addNumbers(1, 2));

    String expectedOut = "http://www.w3.org/2005/08/addressing";
    String expectedIn = "http://www.w3.org/2005/08/addressing";

    assertTrue(output.toString().indexOf(expectedOut) == -1);
    assertTrue(input.toString().indexOf(expectedIn) == -1);
}
 
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: MTOMBindingTypeTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDetail() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    ByteArrayOutputStream output = setupOutLogging();

    Holder<byte[]> photo = new Holder<>("CXF".getBytes());
    Holder<Image> image = new Holder<>(getImage("/java.jpg"));

    Hello port = getPort();

    SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
    binding.setMTOMEnabled(true);


    port.detail(photo, image);

    String expected = "<xop:Include ";
    assertTrue(output.toString().indexOf(expected) != -1);
    assertTrue(input.toString().indexOf(expected) != -1);

    assertEquals("CXF", new String(photo.value));
    assertNotNull(image.value);
}
 
Example #7
Source File: JaxWsHandler.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Set whether SOAP requests should use compression.
 *
 * @param soapClient the client to set compression settings for
 * @param compress whether or not to use compression
 */
@Override
public void setCompression(BindingProvider soapClient, boolean compress) {
  Map<String, String> headersMap = Maps.newHashMap();
  if (compress) {
    headersMap.put("Accept-Encoding", "gzip");
    headersMap.put("Content-Encoding", "gzip");
    putAllHttpHeaders(soapClient, headersMap);
  } else {
    @SuppressWarnings("unchecked") // HTTP Headers in JAXWS are always a map of
                                   // String to List of String.
    Map<String, List<String>> httpHeaders =
        (Map<String, List<String>>) soapClient.getRequestContext().get(
            MessageContext.HTTP_REQUEST_HEADERS);
    if (httpHeaders != null) {
      httpHeaders.remove("Accept-Encoding");
      httpHeaders.remove("Content-Encoding");
    }
  }
}
 
Example #8
Source File: RequestContext.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void fillSOAPAction(Packet packet, boolean isAddressingEnabled) {
    final boolean p = packet.packetTakesPriorityOverRequestContext;
    final String  localSoapAction    = p ? packet.soapAction : soapAction;
    final Boolean localSoapActionUse = p ? (Boolean) packet.invocationProperties.get(BindingProvider.SOAPACTION_USE_PROPERTY)
                                         : soapActionUse;

    //JAX-WS-596: Check the semantics of SOAPACTION_USE_PROPERTY before using the SOAPACTION_URI_PROPERTY for
    // SoapAction as specified in the javadoc of BindingProvider. The spec seems to be little contradicting with
    //  javadoc and says that the use property effects the sending of SOAPAction property.
    // Since the user has the capability to set the value as "" if needed, implement the javadoc behavior.
    if ((localSoapActionUse != null && localSoapActionUse) || (localSoapActionUse == null && isAddressingEnabled)) {
        if (localSoapAction != null) {
            packet.soapAction = localSoapAction;
        }
    }

    if ((!isAddressingEnabled && (localSoapActionUse == null || !localSoapActionUse)) && localSoapAction != null) {
        LOGGER.warning("BindingProvider.SOAPACTION_URI_PROPERTY is set in the RequestContext but is ineffective," +
                " Either set BindingProvider.SOAPACTION_USE_PROPERTY to true or enable AddressingFeature");
    }
}
 
Example #9
Source File: BesDAOTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void getClientForBESTechnologyManager_INTERNAL_userPwdNotInConfig_userInTS()
        throws MalformedURLException, BadResultException,
        APPlatformException {
    // given
    Map<String, Setting> proxySettings = getSettingsForMode("INTERNAL");
    Map<String, Setting> controllerSettings = getControllerSettings(true,
            true, false);
    BesDAO besDAO = mockWebServiceSetup(proxySettings, controllerSettings);
    ServiceInstance si = getServiceInstanceWithParameters(true, true);

    // when
    IdentityService client = besDAO.getBESWebService(IdentityService.class,
            si);

    // then
    verify(besDAO, times(1)).setUserCredentialsInContext(
            (BindingProvider) client, USER_TM_TechSvc, USER_PWD_TM_TechSvc,
            proxySettings);
}
 
Example #10
Source File: DoubleItPortTypeImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public int doubleIt(int numberToDouble) {
    // Delegate request to a provider
    URL wsdl = DoubleItPortTypeImpl.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2SupportingPort");
    DoubleItPortType transportSAML2SupportingPort =
        service.getPort(portQName, DoubleItPortType.class);
    try {
        updateAddressPort(transportSAML2SupportingPort, getPort());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    //
    // Get the principal from the request context and construct a SAML Assertion
    //
    Saml2CallbackHandler callbackHandler = new Saml2CallbackHandler(wsc.getUserPrincipal());
    ((BindingProvider)transportSAML2SupportingPort).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );

    return transportSAML2SupportingPort.doubleIt(numberToDouble);
}
 
Example #11
Source File: X509AsymmetricBindingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testX509SAML2() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509AsymmetricBindingTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = X509AsymmetricBindingTest.class.getResource("DoubleItAsymmetric.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricSAML2Port");
    DoubleItPortType port =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);

    TokenTestUtils.updateSTSPort((BindingProvider)port, STSPORT2);

    doubleIt(port, 30);

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example #12
Source File: CalculatorTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
/**
 * Create a webservice client using wsdl url
 *
 * @throws Exception
 */
//START SNIPPET: webservice
@Test
public void remoteCallWithSslClient() throws Exception {
    // create the service from the WSDL
    final URL url = new URL(base.toExternalForm() + "webservices/CalculatorImpl?wsdl");
    final QName calcServiceQName = new QName("http://superbiz.org/wsdl", "CalculatorWsService");
    final Service calcService = Service.create(url, calcServiceQName);

    assertNotNull(calcService);

    // get the port for the service
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);

    // switch the target URL for invocation to HTTPS
    ((BindingProvider) calc).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://localhost:8443/app/webservices/CalculatorImpl");

    // add the SSL Client certificate, set the trust store and the hostname verifier
    setupTLS(calc);

    // call the remote JAX-WS webservice
    assertEquals(10, calc.sum(4, 6));
    assertEquals(12, calc.multiply(3, 4));
}
 
Example #13
Source File: BesDAOTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void setUserCredentialsInContext_SAML_SP() {
    // given
    Map<String, Setting> settings = getSettingsForMode("SAML_SP");
    BindingProvider client = Mockito.mock(BindingProvider.class);
    Map<String, String> context = new HashMap<>();
    Mockito.doReturn(context).when(client).getRequestContext();

    // when
    besDAO.setUserCredentialsInContext(client, USER, PASSWORD, settings);

    // then
    assertNull(client.getRequestContext().get(
            BindingProvider.USERNAME_PROPERTY));
    assertNull(client.getRequestContext().get(
            BindingProvider.PASSWORD_PROPERTY));
    assertEquals(USER,
            client.getRequestContext().get(XWSSConstants.USERNAME_PROPERTY));
    assertEquals(PASSWORD,
            client.getRequestContext().get(XWSSConstants.PASSWORD_PROPERTY));
}
 
Example #14
Source File: SecondClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static SecondServiceAT newInstance() throws Exception {
    URL wsdlLocation = new URL("http://localhost:8082/Service/SecondServiceAT?wsdl");
    QName serviceName = new QName("http://service.ws.sample", "SecondServiceATService");
    QName portName = new QName("http://service.ws.sample", "SecondServiceAT");

    Service service = Service.create(wsdlLocation, serviceName);
    SecondServiceAT client = service.getPort(portName, SecondServiceAT.class);


    List<Handler> handlerChain = new ArrayList<>();
    JaxWSTxOutboundBridgeHandler txOutboundBridgeHandler = new JaxWSTxOutboundBridgeHandler();
    EnabledWSTXHandler wstxHandler = new EnabledWSTXHandler();

    handlerChain.add(txOutboundBridgeHandler);
    handlerChain.add(wstxHandler);

    ((BindingProvider)client).getBinding().setHandlerChain(handlerChain);

    return client;
}
 
Example #15
Source File: BasicConnection.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void populateContextMap(String url, String username, String password) {
    Map<String, Object> context = ((BindingProvider) vimPort).getRequestContext();
    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    context.put(BindingProvider.USERNAME_PROPERTY, username);
    context.put(BindingProvider.PASSWORD_PROPERTY, password);
    context.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
}
 
Example #16
Source File: SecurityPolicyTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXF3041() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();

    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    DoubleItPortType pt;

    QName portQName = new QName(NAMESPACE, "DoubleItPortCXF3041");
    pt = service.getPort(portQName, DoubleItPortType.class);

    updateAddressPort(pt, PORT);
    ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                  new KeystorePasswordCallback());
    ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                  "alice.properties");
    ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                  "bob.properties");

    // DOM
    assertEquals(10, pt.doubleIt(5));

    // Streaming
    SecurityTestUtil.enableStreaming(pt);
    assertEquals(10, pt.doubleIt(5));

    ((java.io.Closeable)pt).close();
    bus.shutdown(true);
}
 
Example #17
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 #18
Source File: SecurityTestUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void enableStreaming(DoubleItPortType port) {
    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
    );
    ((BindingProvider)port).getResponseContext().put(
        SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
    );
}
 
Example #19
Source File: TransportBindingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSAML2SymmetricEndorsing() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TransportBindingTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = TransportBindingTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2SymmetricEndorsingPort");
    DoubleItPortType transportSaml1Port =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportSaml1Port, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider)transportSaml1Port, test.getStsPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportSaml1Port);
    }

    doubleIt(transportSaml1Port, 25);

    ((java.io.Closeable)transportSaml1Port).close();
    bus.shutdown(true);
}
 
Example #20
Source File: ClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicAuth() throws Exception {
    Service service = Service.create(serviceName);
    service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/",
                    "http://localhost:" + PORT + "/SoapContext/SoapPort");
    Greeter greeter = service.getPort(fakePortName, Greeter.class);

    try {
        //try the jaxws way
        BindingProvider bp = (BindingProvider)greeter;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        String s = greeter.greetMe("secure");
        assertEquals("Hello BJ", s);
        bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
        bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);

        //try setting on the conduit directly
        Client client = ClientProxy.getClient(greeter);
        HTTPConduit httpConduit = (HTTPConduit)client.getConduit();
        AuthorizationPolicy policy = new AuthorizationPolicy();
        policy.setUserName("BJ2");
        policy.setPassword("pswd");
        httpConduit.setAuthorization(policy);

        s = greeter.greetMe("secure");
        assertEquals("Hello BJ2", s);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
}
 
Example #21
Source File: ClientServerMixedStyleTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXF885() throws Exception {
    Service serv = Service.create(new QName("http://example.com", "MixedTest"));
    MixedTest test = serv.getPort(MixedTest.class);
    ((BindingProvider)test).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                    "http://localhost:" + PORT + "/cxf885");
    String ret = test.hello("A", "B");
    assertEquals("Hello A and B", ret);

    String ret2 = test.simple("Dan");
    assertEquals("Hello Dan", ret2);

    String ret3 = test.tripple("A", "B", "C");
    assertEquals("Tripple: A B C", ret3);

    String ret4 = test.simple2(24);
    assertEquals("Int: 24", ret4);

    serv = Service.create(new URL("http://localhost:" + PORT + "/cxf885?wsdl"),
                          new QName("http://example.com", "MixedTestImplService"));
    test = serv.getPort(new QName("http://example.com", "MixedTestImplPort"),
                        MixedTest.class);

    ret = test.hello("A", "B");
    assertEquals("Hello A and B", ret);

    ret2 = test.simple("Dan");
    assertEquals("Hello Dan", ret2);

    ret3 = test.tripple("A", "B", "C");
    assertEquals("Tripple: A B C", ret3);

    ret4 = test.simple2(24);
    assertEquals("Int: 24", ret4);
}
 
Example #22
Source File: UDDIReplicationImpl.java    From juddi with Apache License 2.0 5 votes vote down vote up
private synchronized UDDIReplicationPortType getReplicationClient(String node) {
        if (cache.containsKey(node)) {
                return cache.get(node);
        }
        UDDIService svc = new UDDIService();
        UDDIReplicationPortType replicationClient = svc.getUDDIReplicationPort();
        TransportSecurityHelper.applyTransportSecurity((BindingProvider) replicationClient);

        EntityManager em = PersistenceManager.getEntityManager();
        EntityTransaction tx = em.getTransaction();
        try {
                tx.begin();
                StringBuilder sql = new StringBuilder();
                sql.append("select c from ReplicationConfiguration c order by c.serialNumber desc");
                //sql.toString();
                Query qry = em.createQuery(sql.toString());
                qry.setMaxResults(1);

                org.apache.juddi.model.ReplicationConfiguration resultList = (org.apache.juddi.model.ReplicationConfiguration) qry.getSingleResult();
                for (Operator o : resultList.getOperator()) {
                        if (o.getOperatorNodeID().equalsIgnoreCase(node)) {
                                ((BindingProvider) replicationClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, o.getSoapReplicationURL());
                                cache.put(node, replicationClient);
                                return replicationClient;
                        }
                }
                tx.rollback();

        } catch (Exception ex) {
                logger.fatal("Node not found!" + node, ex);
        } finally {
                if (tx.isActive()) {
                        tx.rollback();
                }
                em.close();
        }
        //em.close();
        return null;

}
 
Example #23
Source File: JaxWsPortClientInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Prepare the given JAX-WS port stub, applying properties to it.
 * Called by {@link #prepare}.
 * @param stub the current JAX-WS port stub
 * @see #setUsername
 * @see #setPassword
 * @see #setEndpointAddress
 * @see #setMaintainSession
 * @see #setCustomProperties
 */
protected void preparePortStub(Object stub) {
	Map<String, Object> stubProperties = new HashMap<>();
	String username = getUsername();
	if (username != null) {
		stubProperties.put(BindingProvider.USERNAME_PROPERTY, username);
	}
	String password = getPassword();
	if (password != null) {
		stubProperties.put(BindingProvider.PASSWORD_PROPERTY, password);
	}
	String endpointAddress = getEndpointAddress();
	if (endpointAddress != null) {
		stubProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
	}
	if (isMaintainSession()) {
		stubProperties.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
	}
	if (isUseSoapAction()) {
		stubProperties.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
	}
	String soapActionUri = getSoapActionUri();
	if (soapActionUri != null) {
		stubProperties.put(BindingProvider.SOAPACTION_URI_PROPERTY, soapActionUri);
	}
	stubProperties.putAll(getCustomProperties());
	if (!stubProperties.isEmpty()) {
		if (!(stub instanceof BindingProvider)) {
			throw new RemoteLookupFailureException("Port stub of class [" + stub.getClass().getName() +
					"] is not a customizable JAX-WS stub: it does not implement interface [javax.xml.ws.BindingProvider]");
		}
		((BindingProvider) stub).getRequestContext().putAll(stubProperties);
	}
}
 
Example #24
Source File: AccessProtectedServiceResource.java    From dropwizard-jaxws with Apache License 2.0 5 votes vote down vote up
@GET
public String getEcho() {
    try {

        BindingProvider bp = (BindingProvider)javaFirstService;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "johndoe");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "secret");

        return this.javaFirstService.echo("Hello from the protected service!");
    }
    catch(JavaFirstService.JavaFirstServiceException jfse) {
        throw new WebApplicationException(jfse);
    }
}
 
Example #25
Source File: JaxWsClient.java    From spring-boot-cxf-integration-example with MIT License 5 votes vote down vote up
/**
 * Loads the content with the specified name from the WebService
 * 
 * @param name The name of the content
 * @return The loaded content
 * @throws IOException If an IO error occurs
 */
public DataHandler loadContent(String name) throws IOException {
    ContentStoreHttpPortService service = new ContentStoreHttpPortService();
    ContentStoreHttpPort loadContentPort = service.getContentStoreHttpPortSoap11();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) loadContentPort).getBinding();
    binding.setMTOMEnabled(true);

    LoadContentRequest request = objectFactory.createLoadContentRequest();
    request.setName(name);
    LoadContentResponse response = loadContentPort.loadContent(request);
    DataHandler content = response.getContent();
    return content;
}
 
Example #26
Source File: APPAuthenticationServiceBeanIT.java    From development with Apache License 2.0 5 votes vote down vote up
public VOUserDetails authenticate(Map<String, Object> requestContext) {
    Object user = requestContext
            .get(useSSO ? XWSSConstants.USERNAME_PROPERTY
                    : BindingProvider.USERNAME_PROPERTY);
    Object pwd = requestContext
            .get(useSSO ? XWSSConstants.PASSWORD_PROPERTY
                    : BindingProvider.PASSWORD_PROPERTY);
    if (user != null) {
        Long userKey = null;
        if (useSSO) {
            VOUserDetails userDetails = byId.get(user);
            if (userDetails != null) {
                userKey = Long.valueOf(userDetails.getKey());
            } else {
                throw new ClientTransportException(
                        new RuntimeException());
            }
        } else {
            userKey = Long.valueOf(user.toString());
        }
        if (passwordsByKey.get(userKey) != null
                && passwordsByKey.get(userKey).equals(pwd)) {
            return byKey.get(userKey);
        }
    }
    throw new ClientTransportException(new RuntimeException());
}
 
Example #27
Source File: HttpTransportPipe.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void addCookies(Packet context, Map<String, List<String>> reqHeaders) throws IOException {
    Boolean shouldMaintainSessionProperty =
            (Boolean) context.invocationProperties.get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
    if (shouldMaintainSessionProperty != null && !shouldMaintainSessionProperty) {
        return;         // explicitly turned off
    }
    if (sticky || (shouldMaintainSessionProperty != null && shouldMaintainSessionProperty)) {
        Map<String, List<String>> rememberedCookies = cookieJar.get(context.endpointAddress.getURI(), reqHeaders);
        processCookieHeaders(reqHeaders, rememberedCookies, "Cookie");
        processCookieHeaders(reqHeaders, rememberedCookies, "Cookie2");
    }
}
 
Example #28
Source File: JaxWsHandler.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Clears all of the SOAP headers from the given SOAP client.
 *
 * @param soapClient the client to remove the headers from
 */
@Override
public void clearHeaders(BindingProvider soapClient) {
  getContextHandlerFromClient(soapClient).clearHeaders();
  soapClient.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
      new HashMap<String, List<String>>());
}
 
Example #29
Source File: ClientAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testClientInvalidCertChain() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ClientAuthTest.class.getResource("client-auth-invalid2.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    try {
        port.greetMe("Kitty");
        fail("Failure expected on no trusted cert");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example #30
Source File: HttpTransportPipe.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void recordCookies(Packet context, HttpClientTransport con) throws IOException {
    Boolean shouldMaintainSessionProperty =
            (Boolean) context.invocationProperties.get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
    if (shouldMaintainSessionProperty != null && !shouldMaintainSessionProperty) {
        return;         // explicitly turned off
    }
    if (sticky || (shouldMaintainSessionProperty != null && shouldMaintainSessionProperty)) {
        cookieJar.put(context.endpointAddress.getURI(), con.getHeaders());
    }
}