Java Code Examples for javax.xml.soap.SOAPElement#addAttribute()

The following examples show how to use javax.xml.soap.SOAPElement#addAttribute() . 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: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 7 votes vote down vote up
private void addClientElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {
  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getClientObjectType() != null ? conf.getClientObjectType() : XroadObjectType.SUBSYSTEM;
  SOAPElement client = header.addChildElement("client", protocol.getNamespacePrefix());
  client.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement clientXRoadInstance = client.addChildElement("xRoadInstance", "id");
  clientXRoadInstance.addTextNode(conf.getClientXRoadInstance());
  SOAPElement clientMemberClass = client.addChildElement("memberClass", "id");
  clientMemberClass.addTextNode(conf.getClientMemberClass());
  SOAPElement clientMemberCode = client.addChildElement("memberCode", "id");
  clientMemberCode.addTextNode(conf.getClientMemberCode());

  if (StringUtils.isNotBlank(conf.getClientSubsystemCode())) {
    SOAPElement clientSubsystemCode = client.addChildElement("subsystemCode", "id");
    clientSubsystemCode.addTextNode(conf.getClientSubsystemCode());
  }
}
 
Example 2
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 3
Source File: SaajStaxWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void addAttibuteToElement(SOAPElement element, String prefix, String ns, String ln, String value)
        throws XMLStreamException {
    try {
        if (ns == null) {
            element.setAttributeNS("", ln, value);
        } else {
            QName name = prefix == null ? new QName(ns, ln) : new QName(ns, ln, prefix);
            element.addAttribute(name, value);
        }
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 4
Source File: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addFaultReasonText(String text, java.util.Locale locale)
    throws SOAPException {

    if (locale == null) {
        log.severe("SAAJ0430.ver1_2.locale.required");
        throw new SOAPException("locale is required and must not be null");
    }

    // Fault Reason has similar semantics as faultstring
    if (this.faultStringElement == null)
        findReasonElement();
    SOAPElement reasonText;

    if (this.faultStringElement == null) {
        this.faultStringElement = addSOAPFaultElement("Reason");
        reasonText =
            this.faultStringElement.addChildElement(
                getFaultReasonTextName());
    } else {
        removeDefaultFaultString();
        reasonText = getFaultReasonTextElement(locale);
        if (reasonText != null) {
            reasonText.removeContents();
        } else {
            reasonText =
                this.faultStringElement.addChildElement(
                    getFaultReasonTextName());
        }
    }

    String xmlLang = localeToXmlLang(locale);
    reasonText.addAttribute(getXmlLangName(), xmlLang);
    reasonText.addTextNode(text);
}
 
Example 5
Source File: ConsumerGateway.java    From xroad-rest-gateway with European Union Public License 1.1 5 votes vote down vote up
protected void handleAttachment(ServiceRequest request, SOAPElement soapRequest, SOAPEnvelope envelope, String attachmentData) throws SOAPException {
    logger.debug("Request body was found from the request. Add request body as SOAP attachment. Content type is \"{}\".", this.contentType);
    SOAPElement data = soapRequest.addChildElement(envelope.createName(Constants.PARAM_REQUEST_BODY));
    data.addAttribute(envelope.createName("href"), Constants.PARAM_REQUEST_BODY);
    AttachmentPart attachPart = request.getSoapMessage().createAttachmentPart(attachmentData, this.contentType);
    attachPart.setContentId(Constants.PARAM_REQUEST_BODY);
    request.getSoapMessage().addAttachmentPart(attachPart);

}
 
Example 6
Source File: SAAJInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException {
    if (events != null) {
        for (XMLEvent ev : events) {
            if (ev.isNamespace()) {
                el.addNamespaceDeclaration(((Namespace)ev).getPrefix(), ((Namespace)ev).getNamespaceURI());
            } else if (ev.isAttribute()) {
                el.addAttribute(((Attribute)ev).getName(), ((Attribute)ev).getValue());
            }
        }
    }
}
 
Example 7
Source File: SaajStaxWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void addAttibuteToElement(SOAPElement element, String prefix, String ns, String ln, String value)
        throws XMLStreamException {
    try {
        if (ns == null) {
            element.setAttributeNS("", ln, value);
        } else {
            QName name = prefix == null ? new QName(ns, ln) : new QName(ns, ln, prefix);
            element.addAttribute(name, value);
        }
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 8
Source File: RmvikiXTeeServiceImpl.java    From j-road with Apache License 2.0 5 votes vote down vote up
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
  callback.doWithMessage(message);
  SOAPMessage extractedMessage = SOAPUtil.extractSoapMessage(message);
  try {
    Node operation = SOAPUtil.getFirstNonTextChild(extractedMessage.getSOAPBody());
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement p1 = factory.createElement("p1");
    p1.addAttribute(factory.createName("href"), "cid:manus");
    operation.appendChild(operation.getOwnerDocument().importNode(p1, true));
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Source File: SaajStaxWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void addAttibuteToElement(SOAPElement element, String prefix, String ns, String ln, String value)
        throws XMLStreamException {
    try {
        if (ns == null) {
            element.setAttributeNS("", ln, value);
        } else {
            QName name = prefix == null ? new QName(ns, ln) : new QName(ns, ln, prefix);
            element.addAttribute(name, value);
        }
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
 
Example 10
Source File: ProviderGateway.java    From xroad-rest-gateway with European Union Public License 1.1 5 votes vote down vote up
protected void handleAttachment(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    SOAPElement data = soapResponse.addChildElement(envelope.createName("data"));
    data.addAttribute(envelope.createName("href"), "response_data");
    AttachmentPart attachPart = response.getSoapMessage().createAttachmentPart(response.getResponseData(), contentType);
    attachPart.setContentId("response_data");
    response.getSoapMessage().addAttachmentPart(attachPart);
}
 
Example 11
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 12
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 5 votes vote down vote up
private void addServiceElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {

  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getServiceObjectType() != null ? conf.getServiceObjectType() : XroadObjectType.SERVICE;

  SOAPElement service = header.addChildElement("service", protocol.getNamespacePrefix());
  service.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement serviceXRoadInstance = service.addChildElement("xRoadInstance", "id");
  serviceXRoadInstance.addTextNode(conf.getServiceXRoadInstance());
  SOAPElement serviceMemberClass = service.addChildElement("memberClass", "id");
  serviceMemberClass.addTextNode(conf.getServiceMemberClass());
  SOAPElement serviceMemberCode = service.addChildElement("memberCode", "id");
  serviceMemberCode.addTextNode(conf.getServiceMemberCode());

  if (StringUtils.isNotBlank(conf.getServiceSubsystemCode())) {
    SOAPElement subsystemCode = service.addChildElement("subsystemCode", "id");
    subsystemCode.addTextNode(conf.getServiceSubsystemCode());
  }

  SOAPElement database = service.addChildElement("serviceCode", "id");
  database.addTextNode(conf.getMethod());

  if(StringUtils.isNotBlank(conf.getVersion())){
    SOAPElement serviceVersion = service.addChildElement("serviceVersion", "id");
    serviceVersion.addTextNode(conf.getVersion());
  }

}
 
Example 13
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 14
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example 15
Source File: TestMtomProviderImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SOAPMessage invoke(final SOAPMessage request) {
    try {
        System.out.println("=== Received client request ===");

        // create the SOAPMessage
        SOAPMessage message = MessageFactory.newInstance().createMessage();
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        SOAPBody body = envelope.getBody();


        SOAPBodyElement testResponse = body
            .addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types"));
        SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types");
        name.setTextContent("return detail + call detail");
        SOAPElement attachinfo = testResponse.addChildElement(
                                     "attachinfo", null, "http://cxf.apache.org/mime/types");
        SOAPElement include = attachinfo.addChildElement("Include", "xop",
                                                            "http://www.w3.org/2004/08/xop/include");

        int fileSize = 0;
        try (InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl")) {
            for (int i = pre.read(); i != -1; i = pre.read()) {
                fileSize++;
            }
        }

        int count = 50;
        byte[] data = new byte[fileSize *  count];
        for (int x = 0; x < count; x++) {
            this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data,
                                                                            fileSize * x,
                                                                            fileSize);
        }


        DataHandler dh = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));

        // create the image attachment
        AttachmentPart attachment = message.createAttachmentPart(dh);
        attachment.setContentId("mtom_xop.wsdl");
        message.addAttachmentPart(attachment);
        System.out
            .println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize());

        // add the reference to the image attachment
        include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId());

        return message;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 16
Source File: AbstractSoapEncoder.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a SOAPDetail element from SOS exception document.
 *
 * @param detail
 *            SOAPDetail
 * @param exception
 *            SOS Exception document
 *
 * @throws SOAPException
 *             if an error occurs.
 *
 * @deprecated javax.xml.soap.* is no longer supported from 8.0 because it
 *             was removed from Java
 */
@Deprecated
private void createSOAPFaultDetail(Detail detail, CodedException exception) throws SOAPException {
    SOAPElement exRep = detail.addChildElement(OWSConstants.QN_EXCEPTION);
    exRep.addNamespaceDeclaration(OWSConstants.NS_OWS_PREFIX, OWSConstants.NS_OWS);
    String code = exception.getCode()
            .toString();
    String locator = exception.getLocator();
    StringBuilder exceptionText = new StringBuilder();
    exceptionText.append(exception.getMessage());
    exceptionText.append('\n');
    if (exception.getCause() != null) {
        exceptionText.append('\n')
                .append("[EXCEPTION]: ")
                .append('\n');
        if (exception.getCause()
                .getLocalizedMessage() != null
                && !exception.getCause()
                        .getLocalizedMessage()
                        .isEmpty()) {
            exceptionText.append(exception.getCause()
                    .getLocalizedMessage());
            exceptionText.append('\n');
        }
        if (exception.getCause()
                .getMessage() != null
                && !exception.getCause()
                        .getMessage()
                        .isEmpty()) {
            exceptionText.append(exception.getCause()
                    .getMessage());
            exceptionText.append('\n');
        }
    }
    exRep.addAttribute(new QName(OWSConstants.EN_EXCEPTION_CODE), code);
    if (locator != null && !locator.isEmpty()) {
        exRep.addAttribute(new QName(OWSConstants.EN_LOCATOR), locator);
    }
    if (exceptionText.length() != 0) {
        SOAPElement execText = exRep.addChildElement(OWSConstants.QN_EXCEPTION_TEXT);
        execText.setTextContent(exceptionText.toString());
    }
}
 
Example 17
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 18
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 19
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private void processRequiredElements(WsAddressingHeader header, SOAPHeader soapHeader) throws SOAPException {
   SOAPElement actionElement = soapHeader.addChildElement(ACTION);
   actionElement.addAttribute(MUST_UNDERSTAND, header.getMustUnderstand());
   actionElement.setTextContent(header.getAction().toString());
}
 
Example 20
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyXsi() throws Exception {
    if (!shouldRunTest("StructWithAnyXsi")) {
        return;
    }
    StructWithAny swa = new StructWithAny();
    swa.setName("Name");
    swa.setAddress("Some Address");
    StructWithAny yOrig = new StructWithAny();
    yOrig.setName("Name2");
    yOrig.setAddress("Some Other Address");

    SOAPFactory sf = SOAPFactory.newInstance();
    Name elementName = sf.createName("UKAddress", "", "http://apache.org/type_test");
    Name xsiAttrName = sf.createName("type", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
    SOAPElement x = sf.createElement(elementName);
    x.addNamespaceDeclaration("tns", "http://apache.org/type_test");
    x.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    x.addAttribute(xsiAttrName, "tns:UKAddressType11");
    x.addTextNode("This is the text of the node for the first struct");

    Name elementName2 = sf.createName("UKAddress", "", "http://apache.org/type_test");
    Name xsiAttrName2 = sf.createName("type", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
    SOAPElement x2 = sf.createElement(elementName2);
    x2.addNamespaceDeclaration("tns", "http://apache.org/type_test");
    x2.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    x2.addAttribute(xsiAttrName2, "tns:UKAddressType22");
    x2.addTextNode("This is the text of the node for the second struct");

    swa.setAny(x);
    yOrig.setAny(x2);

    Holder<StructWithAny> y = new Holder<>(yOrig);
    Holder<StructWithAny> z = new Holder<>();
    StructWithAny ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAny(swa, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAny(swa, y, z);
    } else {
        ret = rpcClient.testStructWithAny(swa, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAny(swa, y.value);
        assertEqualsStructWithAny(yOrig, z.value);
        assertEqualsStructWithAny(swa, ret);
    }
}