org.apache.axis.client.AxisClient Java Examples

The following examples show how to use org.apache.axis.client.AxisClient. 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: HttpHandlerTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a valid XML response results in a successful invocation of the handler that produces
 * a valid SOAP envelope.
 */
@Test
public void testInvokeReturnsValidXml() throws IOException {
  // Unlike the failure tests below, create the MessageContext here with an actual AxisClient,
  // not a mock AxisEngine. Otherwise, the call to getSOAPEnvelope below will fail.
  MessageContext messageContext = new MessageContext(new AxisClient());
  messageContext.setRequestMessage(requestMessage);
  messageContext.setProperty(MessageContext.TRANS_URL, mockHttpServer.getServerUrl());
  SoapResponseXmlProvider.getTestSoapResponse(API_VERSION);
  mockHttpServer.setMockResponse(
      new MockResponse(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION)));

  httpHandler.invoke(messageContext);
  assertNotNull(
      "SOAP envelope of response is null", messageContext.getResponseMessage().getSOAPEnvelope());
}
 
Example #2
Source File: AdsAxisEngineConfigurationFactoryTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the client engine config returned by the factory when compression is disabled
 * matches the default client config.
 */
@Test
public void testGetClientEngineConfig_compressionDisabled() throws Exception {
  when(adsLibConfiguration.isCompressionEnabled()).thenReturn(false);

  assertNull(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE
      + " property is unexpectedly set",
      System.getProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE));

  EngineConfiguration clientEngineConfig = adsAxisConfigFactory.getClientEngineConfig();
  assertNotNull("No client engine config returned", clientEngineConfig);

  AxisClient axisClient = new AxisClient(clientEngineConfig);

  assertTransportConfiguration(axisClient, defaultAxisClient);

  assertTransportConfiguration(new AxisServer(adsAxisConfigFactory.getServerEngineConfig()),
      defaultAxisServer);
}
 
Example #3
Source File: AdsAxisEngineConfigurationFactoryTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the client engine config returned by the factory when compression is enabled matches
 * the settings in ads-axis-client.wsdd.
 */
@Test
public void testGetClientEngineConfig_compressionEnabled() throws Exception {
  when(adsLibConfiguration.isCompressionEnabled()).thenReturn(true);

  assertNull(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE
      + " property is unexpectedly set",
      System.getProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE));

  EngineConfiguration clientEngineConfig = adsAxisConfigFactory.getClientEngineConfig();
  assertNotNull("No client engine config returned", clientEngineConfig);

  AxisClient axisClient = new AxisClient(clientEngineConfig);

  assertEquals(HttpHandler.class, getTransport(axisClient, "http").getPivotHandler().getClass());

  assertEquals(org.apache.axis.transport.local.LocalSender.class,
      getTransport(axisClient, "local").getPivotHandler().getClass());

  assertEquals(org.apache.axis.transport.java.JavaSender.class,
      getTransport(axisClient, "java").getPivotHandler().getClass());

  assertTransportConfiguration(new AxisServer(adsAxisConfigFactory.getServerEngineConfig()),
      defaultAxisServer);
}
 
Example #4
Source File: AdsAxisEngineConfigurationFactoryTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);

  adsAxisConfigFactory = new AdsAxisEngineConfigurationFactory(adsLibConfiguration);

  EngineConfigurationFactory defaultAxisConfigFactory =
      EngineConfigurationFactoryFinder.newFactory();
  defaultAxisClient = new AxisClient(defaultAxisConfigFactory.getClientEngineConfig());
  defaultAxisServer = new AxisServer(defaultAxisConfigFactory.getServerEngineConfig());
}
 
Example #5
Source File: AdsAxisEngineConfigurationFactoryTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetClientEngineConfig_factoryOverrideSet() throws Exception {
  List<Boolean> compressionEnabledSettings = Lists.newArrayList(Boolean.TRUE, Boolean.FALSE);

  try {
    // Set the client config file system property to the default client config WSDD in the
    // Axis library and then verify that regardless of the ads lib configuration's compression
    // setting, the axis client's transport is configured according to the default configuration
    // factory, NOT the AdsAxisEngineConfigurationFactory.
    System.setProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE,
        "/org/apache/axis/client/client-config.wsdd");
    for (Boolean compressionEnabledSetting : compressionEnabledSettings) {
      when(adsLibConfiguration.isCompressionEnabled()).thenReturn(compressionEnabledSetting);
      EngineConfiguration clientEngineConfig = adsAxisConfigFactory.getClientEngineConfig();
      assertNotNull("No client engine config returned", clientEngineConfig);

      AxisClient axisClient = new AxisClient(clientEngineConfig);

      assertTransportConfiguration(axisClient, defaultAxisClient);

      assertTransportConfiguration(new AxisServer(adsAxisConfigFactory.getServerEngineConfig()),
          defaultAxisServer);
    }
  } finally {
    System.clearProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE);
  }
}
 
Example #6
Source File: AdsAxisEngineConfigurationFactoryTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the axis client's transport configuration matches that of the prototype axis
 * client.
 */
private void assertTransportConfiguration(AxisClient axisClient, AxisClient prototypeAxisClient)
    throws AxisFault {
  for (String transportName : new String[] {"http", "local", "java"}) {
    assertEquals("Pivot handler is not of the expected type",
        getTransport(prototypeAxisClient, transportName).getPivotHandler().getClass(),
        getTransport(axisClient, transportName).getPivotHandler().getClass());
  }
}
 
Example #7
Source File: SoapWrapper.java    From iaf with Apache License 2.0 4 votes vote down vote up
public String signMessage(String soapMessage, String user, String password, boolean passwordDigest) {
	try {
		WSSecurityEngine secEngine = WSSecurityEngine.getInstance();
		WSSConfig config = secEngine.getWssConfig();
		config.setPrecisionInMilliSeconds(false);

		// create context
		AxisClient tmpEngine = new AxisClient(new NullProvider());
		MessageContext msgContext = new MessageContext(tmpEngine);

		InputStream in = new ByteArrayInputStream(soapMessage.getBytes(StreamUtil.DEFAULT_INPUT_STREAM_ENCODING));
		Message msg = new Message(in);
		msg.setMessageContext(msgContext);

		// create unsigned envelope
		SOAPEnvelope unsignedEnvelope = msg.getSOAPEnvelope();
		Document doc = unsignedEnvelope.getAsDocument();

		// create security header and insert it into unsigned envelope
		WSSecHeader secHeader = new WSSecHeader();
		secHeader.insertSecurityHeader(doc);

		// add a UsernameToken
		WSSecUsernameToken tokenBuilder = new WSSecUsernameToken();
		if (passwordDigest) {
			tokenBuilder.setPasswordType(WSConstants.PASSWORD_DIGEST);
		} else {
			tokenBuilder.setPasswordType(WSConstants.PASSWORD_TEXT);
		}
		tokenBuilder.setUserInfo(user, password);
		tokenBuilder.addNonce();
		tokenBuilder.addCreated();
		tokenBuilder.prepare(doc);

		WSSecSignature sign = new WSSecSignature();
		sign.setUsernameToken(tokenBuilder);
		sign.setKeyIdentifierType(WSConstants.UT_SIGNING);
		sign.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
		sign.build(doc, null, secHeader);

		tokenBuilder.prependToHeader(secHeader);

		// add a Timestamp
		WSSecTimestamp timestampBuilder = new WSSecTimestamp();
		timestampBuilder.setTimeToLive(300);
		timestampBuilder.prepare(doc);
		timestampBuilder.prependToHeader(secHeader);

		Document signedDoc = doc;

		return DOM2Writer.nodeToString(signedDoc);

	} catch (Exception e) {
		throw new RuntimeException("Could not sign message", e);
	}
}
 
Example #8
Source File: AxisDeserializer.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public <ResultT> List<ResultT> deserializeBatchJobMutateResults(
    URL url,
    List<TypeMapping> serviceTypeMappings,
    Class<ResultT> resultClass,
    QName resultQName,
    int startIndex,
    int numberResults)
    throws Exception {

  List<ResultT> results = Lists.newArrayList();

  // Build a wrapped input stream from the response.
  InputStream wrappedStream =
      ByteSource.concat(
              ByteSource.wrap(SOAP_START_BODY.getBytes(UTF_8)),
              batchJobHelperUtility.buildWrappedByteSource(url, startIndex, numberResults),
              ByteSource.wrap(SOAP_END_BODY.getBytes(UTF_8)))
          .openStream();

  // Create a MessageContext with a new TypeMappingRegistry that will only
  // contain deserializers derived from serviceTypeMappings and the
  // result class/QName pair.
  MessageContext messageContext = new MessageContext(new AxisClient());
  TypeMappingRegistryImpl typeMappingRegistry = new TypeMappingRegistryImpl(true);
  messageContext.setTypeMappingRegistry(typeMappingRegistry);

  // Construct an Axis deserialization context.
  DeserializationContext deserializationContext =
      new DeserializationContext(
          new InputSource(wrappedStream), messageContext, Message.RESPONSE);

  // Register all type mappings with the new type mapping registry.
  TypeMapping registryTypeMapping =
      typeMappingRegistry.getOrMakeTypeMapping(messageContext.getEncodingStyle());
  registerTypeMappings(registryTypeMapping, serviceTypeMappings);

  // Parse the wrapped input stream.
  deserializationContext.parse();

  // Read the deserialized mutate results from the parsed stream.
  SOAPEnvelope envelope = deserializationContext.getEnvelope();
  MessageElement body = envelope.getFirstBody();

  for (Iterator<?> iter = body.getChildElements(); iter.hasNext(); ) {
    Object child = iter.next();
    MessageElement childElm = (MessageElement) child;
    @SuppressWarnings("unchecked")
    ResultT mutateResult = (ResultT) childElm.getValueAsType(resultQName, resultClass);
    results.add(mutateResult);
  }
  return results;
}