Java Code Examples for org.apache.axis.Constants

The following examples show how to use org.apache.axis.Constants. These examples are extracted from open source projects. 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 Project: tomee   Source File: SeiFactoryImpl.java    License: Apache License 2.0 5 votes vote down vote up
void initialize(Object serviceImpl, ClassLoader classLoader) throws ClassNotFoundException {
    this.serviceImpl = serviceImpl;
    Class serviceEndpointBaseClass = classLoader.loadClass(serviceEndpointClassName);
    serviceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointBaseClass, classLoader);
    Class[] constructorTypes = new Class[]{classLoader.loadClass(GenericServiceEndpoint.class.getName())};
    this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
    this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
    sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
    String encodingStyle = "";
    for (int i = 0; i < operationInfos.length; i++) {
        OperationInfo operationInfo = operationInfos[i];
        Signature signature = operationInfo.getSignature();
        MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
        if (methodProxy == null) {
            throw new ServerRuntimeException("No method proxy for operationInfo " + signature);
        }
        int index = methodProxy.getSuperIndex();
        sortedOperationInfos[index] = operationInfo;
        if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
            encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
        }
    }
    //register our type descriptors
    Service service = ((ServiceImpl) serviceImpl).getService();
    AxisEngine axisEngine = service.getEngine();
    TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
    TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
    typeMapping.register(BigInteger.class, Constants.XSD_UNSIGNEDLONG, new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG), new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
    typeMapping.register(URI.class, Constants.XSD_ANYURI, new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI), new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
    //It is essential that the types be registered before the typeInfos create the serializer/deserializers.
    for (Iterator iter = typeInfo.iterator(); iter.hasNext(); ) {
        TypeInfo info = (TypeInfo) iter.next();
        TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
    }
    TypeInfo.register(typeInfo, typeMapping);
}
 
Example 2
Source Project: googleads-java-lib   Source File: HttpHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new Axis Message based on the contents of the HTTP response.
 *
 * @param httpResponse the HTTP response
 * @return an Axis Message for the HTTP response
 * @throws IOException if unable to retrieve the HTTP response's contents
 * @throws AxisFault if the HTTP response's status or contents indicate an unexpected error, such
 *     as a 405.
 */
private Message createResponseMessage(HttpResponse httpResponse) throws IOException, AxisFault {
  int statusCode = httpResponse.getStatusCode();
  String contentType = httpResponse.getContentType();
  // The conditions below duplicate the logic in CommonsHTTPSender and HTTPSender.
  boolean shouldParseResponse =
      (statusCode > 199 && statusCode < 300)
          || (contentType != null
              && !contentType.equals("text/html")
              && statusCode > 499
              && statusCode < 600);
  // Wrap the content input stream in a notifying stream so the stream event listener will be
  // notified when it is closed.
  InputStream responseInputStream =
      new NotifyingInputStream(httpResponse.getContent(), inputStreamEventListener);
  if (!shouldParseResponse) {
    // The contents are not an XML response, so throw an AxisFault with
    // the HTTP status code and message details.
    String statusMessage = httpResponse.getStatusMessage();
    AxisFault axisFault =
        new AxisFault("HTTP", "(" + statusCode + ")" + statusMessage, null, null);
    axisFault.addFaultDetail(
        Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, String.valueOf(statusCode));
    try (InputStream stream = responseInputStream) {
      byte[] contentBytes = ByteStreams.toByteArray(stream);
      axisFault.setFaultDetailString(
          Messages.getMessage(
              "return01", String.valueOf(statusCode), new String(contentBytes, UTF_8)));
    }
    throw axisFault;
  }
  // Response is an XML response. Do not consume and close the stream in this case, since that
  // will happen later when the response is deserialized by Axis (as confirmed by unit tests for
  // this class).
  Message responseMessage =
      new Message(
          responseInputStream, false, contentType, httpResponse.getHeaders().getLocation());
  responseMessage.setMessageType(Message.RESPONSE);
  return responseMessage;
}
 
Example 3
Source Project: uima-uimaj   Source File: XmlSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getMechanismType() {
  return Constants.AXIS_SAX;
}
 
Example 4
Source Project: uima-uimaj   Source File: BinarySerializer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Serialize an element named name, with the indicated attributes and value.
 *
 * @param name          is the element name
 * @param attributes          are the attributes...serializer is free to add more.
 * @param value          is the value
 * @param context          is the SerializationContext
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Override
public void serialize(QName name, Attributes attributes, Object value,
        SerializationContext context) throws IOException {
  if (value instanceof Serializable) {
    byte[] bytes = SerializationUtils.serialize((Serializable) value);

    // Should we use an attachment? Do so if:
    // (a) attachment support exists and mUseAttachments == true and
    // (b) if we are the server, the client sent us an attachment
    // (so we know client wants attachment support as well)]
    Message msg = context.getCurrentMessage();
    Attachments attachments = msg.getAttachmentsImpl();
    boolean useAttachments = (attachments != null) && mUseAttachments;
    if (useAttachments) {
      useAttachments = !context.getMessageContext().getPastPivot()
              || context.getMessageContext().getRequestMessage().getAttachments().hasNext();
    }
    // if we have attachment support, do this as an attachment
    if (useAttachments) {
      // System.out.println("Creating attachment"); //DEBUG
      SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants();
      DataHandler dataHandler = new DataHandler(new OctetStreamDataSource("test",
              new OctetStream(bytes)));
      Part attachmentPart = attachments.createAttachmentPart(dataHandler);

      AttributesImpl attrs = new AttributesImpl();
      if (attributes != null && 0 < attributes.getLength())
        attrs.setAttributes(attributes); // copy the existing ones.

      int typeIndex = -1;
      if ((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, "type")) != -1) {
        // Found a xsi:type which should not be there for attachments.
        attrs.removeAttribute(typeIndex);
      }

      attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA",
              attachmentPart.getContentIdRef());
      context.startElement(name, attrs);
      context.endElement();
    } else {
      // no attachment support - Base64 encode
      // System.out.println("No attachment support"); //DEBUG
      context.startElement(name, attributes);

      String base64str = Base64.encode(bytes);
      context.writeChars(base64str.toCharArray(), 0, base64str.length());
      context.endElement();
    }

  } else {
    throw new IOException(value.getClass().getName() + " is not serializable.");
  }
}
 
Example 5
Source Project: uima-uimaj   Source File: BinarySerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getMechanismType() {
  return Constants.AXIS_SAX;
}
 
Example 6
Source Project: uima-uimaj   Source File: XmlSerializer_Axis11.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getMechanismType() {
  return Constants.AXIS_SAX;
}
 
Example 7
Source Project: uima-uimaj   Source File: BinarySerializer_Axis11.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Serialize an element named name, with the indicated attributes and value.
 *
 * @param name          is the element name
 * @param attributes          are the attributes...serializer is free to add more.
 * @param value          is the value
 * @param context          is the SerializationContext
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Override
public void serialize(QName name, Attributes attributes, Object value,
        SerializationContext context) throws IOException {
  if (value instanceof Serializable) {
    byte[] bytes = SerializationUtils.serialize((Serializable) value);

    // Should we use an attachment? Do so if:
    // (a) attachment support exists and mUseAttachments == true and
    // (b) if we are the server, the client sent us an attachment
    // (so we know client wants attachment support as well)]
    Message msg = context.getCurrentMessage();
    Attachments attachments = msg.getAttachmentsImpl();
    boolean useAttachments = (attachments != null) && mUseAttachments;
    if (useAttachments) {
      useAttachments = !context.getMessageContext().getPastPivot()
              || context.getMessageContext().getRequestMessage().getAttachments().hasNext();
    }
    // if we have attachment support, do this as an attachment
    if (useAttachments) {
      // System.out.println("Creating attachment"); //DEBUG
      SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants();
      DataHandler dataHandler = new DataHandler(new OctetStreamDataSource("test",
              new OctetStream(bytes)));
      Part attachmentPart = attachments.createAttachmentPart(dataHandler);

      AttributesImpl attrs = new AttributesImpl();
      if (attributes != null && 0 < attributes.getLength())
        attrs.setAttributes(attributes); // copy the existing ones.

      int typeIndex = -1;
      if ((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, "type")) != -1) {
        // Found a xsi:type which should not be there for attachments.
        attrs.removeAttribute(typeIndex);
      }

      attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA",
              attachmentPart.getContentIdRef());
      context.startElement(name, attrs);
      context.endElement();
    } else {
      // no attachment support - Base64 encode
      // System.out.println("No attachment support"); //DEBUG
      context.startElement(name, attributes);

      String base64str = Base64.encode(bytes);
      context.writeChars(base64str.toCharArray(), 0, base64str.length());
      context.endElement();
    }

  } else {
    throw new IOException(value.getClass().getName() + " is not serializable.");
  }
}
 
Example 8
Source Project: uima-uimaj   Source File: BinarySerializer_Axis11.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getMechanismType() {
  return Constants.AXIS_SAX;
}