Java 类javax.xml.soap.MimeHeaders 实例源码

项目:OpenJSharp    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:xrd4j    文件:AdapterUtils.java   
/**
 * Fetches MIME header information from HTTP request object.
 *
 * @param req HTTP request object
 * @return MimeHeaders that were extracted from the HTTP request
 */
public static MimeHeaders getHeaders(HttpServletRequest req) {
    Enumeration enumeration = req.getHeaderNames();
    MimeHeaders headers = new MimeHeaders();

    while (enumeration.hasMoreElements()) {
        String name = (String) enumeration.nextElement();
        String value = req.getHeader(name);

        StringTokenizer values = new StringTokenizer(value, ",");
        while (values.hasMoreTokens()) {
            headers.addHeader(name, values.nextToken().trim());
        }
    }
    return headers;
}
项目:openjdk-jdk10    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:openjdk9    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:atf-toolbox-java    文件:WebServiceAutomationManager.java   
/**
 * createSOAPRequestMessage - create a SOAP message from an object
 *
 * @param webServiceKey
 *            key to locate the web service
 * @param request
 *            - request body content
 * @param action
 *            - SOAP Action string
 * @return SOAPMessage
 * @throws SOAPException
 *             - if there was an error creating the SOAP Connection
 * @throws JAXBException
 *             - if there was an error marshalling the SOAP Message
 */
private SOAPMessage createSOAPRequestMessage(String webServiceKey, Object request, String action) throws SOAPException, JAXBException {
    WebService service = getWebService(webServiceKey);

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", service.getNamespaceURI());

    if (action != null) {
        MimeHeaders headers = message.getMimeHeaders();
        headers.addHeader("SOAPAction", service.getNamespaceURI() + "VerifyEmail");
    }

    // SOAP Body
    SOAPBody body = message.getSOAPBody();

    marshallObject(webServiceKey, request, body);

    message.saveChanges();
    return message;
}
项目:soap-wrapper-lambda    文件:ExampleSoapMessage.java   
public static SOAPMessage create() throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("codecentric", "https://www.codecentric.de");

    SOAPBody envelopeBody = envelope.getBody();
    SOAPElement soapBodyElem = envelopeBody.addChildElement("location", "codecentric");

    SOAPElement place = soapBodyElem.addChildElement("place", "codecentric");
    place.addTextNode("Berlin");

    MimeHeaders headers = message.getMimeHeaders();
    headers.addHeader("SOAPAction", "https://www.codecentric.de/location");

    message.saveChanges();
    return message;
}
项目:hermes    文件:Headers.java   
/**
 * Adds the given name-values header to the given headers object. 
 * 
 * @param headers the headers object.
 * @param name the header name.
 * @param values the header values.
 */
private void addHeaders(Object headers, String name, Object[] values) {
    if (name != null) {
        for (int i=0; i<values.length; i++) {
            if (headers instanceof StringWriter) {
                StringWriter outs = (StringWriter)headers;
                outs.write(name+": "+values[i]+"\r\n");
                continue;
            }
            StringTokenizer subvalues = new StringTokenizer(
                    values[i].toString(), ",");
            while (subvalues.hasMoreTokens()) {
                String subvalue = subvalues.nextToken().trim();
                if (headers instanceof MimeHeaders) {
                    ((MimeHeaders)headers).addHeader(name, subvalue);
                }
                else if (headers instanceof InternetHeaders) {
                    ((InternetHeaders)headers).addHeader(name, subvalue);
                }
            }
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:openxds    文件:SoapRequestBean.java   
private static void printMessage(SOAPMessage message, String headerType) throws IOException, SOAPException {
    if (message != null) {
        //get the mime headers and print them
        System.out.println("\n\nHeader: " + headerType);
        if (message.saveRequired()) {
            message.saveChanges();
        }
        MimeHeaders headers = message.getMimeHeaders();
        printHeaders(headers);

        //print the message itself
        System.out.println("\n\nMessage: " + headerType);
        message.writeTo(System.out);
        System.out.println();
    }
}
项目:AJ    文件:SoapUtil.java   
/**
 * Creates a {@link SOAPMessage} object from the specified byte array.
 *
 * @param content     the raw message to parse the <code>SOAPMessage</code> from
 * @param contentType the HTTP Content-Type value that corresponds to the message. Required in order to determine if
 *                    the message should be parsed as a standard XML message or a multipart message with attachments.
 * @return the SOAPMessage object parsed from the given byte array
 * @throws SOAPException if the message is not a valid SOAP message
 */
public static SOAPMessage parseMessage(byte[] content, String contentType) throws SOAPException {
  ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
  try {
    MessageFactory messageFactory = MessageFactory.newInstance();
    MimeHeaders headers = new MimeHeaders();
    headers.addHeader(HttpUtil.HEADER_CONTENT_TYPE, contentType);
    return messageFactory.createMessage(headers, inputStream);
  } catch (IOException e) {
    /* Should never happen - ByteArrayInputStream in this case is always readable and if its contents are invalid,
     * SOAPException will be thrown instead. */
    throw ExceptionUtil.toUnchecked(e);
  } finally {
    IOUtil.close(inputStream);
  }
}
项目:jbossws-cxf    文件:TestHandler.java   
private void checkContentType(SOAPMessage soapMessage)
{
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   String[] ct = mimeHeaders.getHeader("Content-Type");
   boolean found = false;
   if (ct != null)
   {
      for (int i = 0; i < ct.length; i++)
      {
         if (ct[i].startsWith(contentType))
            found = true;
      }
   }
   if (!found)
      throw new RuntimeException("Expected '" + contentType + "' content-type not found in the headers");
}
项目:jbossws-cxf    文件:ClientMimeHandler.java   
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext)
{
   log.info("handleOutbound");

   // legacy JBossWS-Native approach
   SOAPMessage soapMessage = msgContext.getMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   mimeHeaders.setHeader("Cookie", "client-cookie=true");

   // proper approach through MessageContext.HTTP_REQUEST_HEADERS
   Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
   httpHeaders.put("Cookie", Collections.singletonList("client-cookie=true"));
   msgContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

   inboundCookie = null;

   return true;
}
项目:jbossws-cxf    文件:ClientMimeHandler.java   
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
   log.info("handleInbound");

   //legacy JBossWS-Native approach
   SOAPMessage soapMessage = msgContext.getMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   String[] cookies = mimeHeaders.getHeader("Set-Cookie");

   // proper approach through MessageContext.HTTP_RESPONSE_HEADERS
   if (cookies == null) {
      @SuppressWarnings("unchecked")
      Map<String, List<String>> httpHeaders = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
      List<String> l = httpHeaders.get("Set-Cookie");
      if (l != null && !l.isEmpty()) {
         cookies = l.toArray(new String[l.size()]);
      }
   }

   if (cookies != null && cookies.length == 1)
      inboundCookie = cookies[0];

   return true;
}
项目:jbossws-cxf    文件:ServerMimeHandler.java   
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
   log.info("handleInbound");

   // legacy JBossWS-Native approach...
   SOAPMessage soapMessage = msgContext.getMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   String[] cookies = mimeHeaders.getHeader("Cookie");

   // proper approach through MessageContext.HTTP_REQUEST_HEADERS
   if (cookies == null) {
      @SuppressWarnings("unchecked")
      Map<String, List<String>> httpHeaders = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
      List<String> l = httpHeaders.get("Cookie");
      if (l != null && !l.isEmpty()) {
         cookies = l.toArray(new String[l.size()]);
      }
   }

   if (cookies != null && cookies.length == 1 && cookies[0].equals("client-cookie=true"))
      setCookieOnResponse = true;

   return true;
}
项目:jbossws-cxf    文件:ServerMimeHandler.java   
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext)
{
   log.info("handleOutbound");

   if (setCookieOnResponse)
   {
      // legacy JBossWS-Native approach
      SOAPMessage soapMessage = msgContext.getMessage();
      MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
      mimeHeaders.setHeader("Set-Cookie", "server-cookie=true");

      // proper approach through MessageContext.HTTP_REQUEST_HEADERS
      Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
      httpHeaders.put("Set-Cookie", Collections.singletonList("server-cookie=true"));
      msgContext.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

      setCookieOnResponse = false;
   }

   return true;
}
项目:infobip-open-jdk-8    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:OLD-OpenJDK8    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:wso2-axis2    文件:SOAPBindingProviderTests.java   
public void testSoap12Request(){
    try{
        System.out.println("---------------------------------------");
        System.out.println("test: " + getName());

        Dispatch<SOAPMessage> dispatch=getDispatch();
        String soapMessage = getSOAP12Message();
        System.out.println("soap message ="+soapMessage);
        MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        MimeHeaders header = new MimeHeaders();
        header.addHeader("Content-Type", "application/soap+xml");
        SOAPMessage message = factory.createMessage(header, new ByteArrayInputStream(soapMessage.getBytes()));
        Object obj = dispatch.invoke(message);
        assertTrue(obj!=null && obj instanceof SOAPMessage);
        assertTrue(getVersionURI(message).equals(SOAP12_NS_URI));
        System.out.println("Provider endpoint was able to receive both SOAP 11 and SOAP 12 request");
    }catch(Exception e){
        System.out.println("Expecting that endpoint will be able to receive soap 12 and soap 11 request");
        System.out.println(e.getMessage());
        fail();

    }
}
项目:wso2-axis2    文件:AttachmentPartImpl.java   
/**
 * Check whether at least one of the headers of this object matches a provided header
 *
 * @param headers
 * @return <b>true</b> if at least one header of this AttachmentPart matches a header in the
 *         provided <code>headers</code> parameter, <b>false</b> if none of the headers of this
 *         AttachmentPart matches at least one of the header in the provided
 *         <code>headers</code> parameter
 */
public boolean matches(MimeHeaders headers) {
    for (Iterator i = headers.getAllHeaders(); i.hasNext();) {
        MimeHeader hdr = (javax.xml.soap.MimeHeader)i.next();
        String values[] = mimeHeaders.getHeader(hdr.getName());
        boolean found = false;
        if (values != null) {
            for (int j = 0; j < values.length; j++) {
                if (!hdr.getValue().equalsIgnoreCase(values[j])) {
                    continue;
                }
                found = true;
                break;
            }
        }
        if (!found) {
            return false;
        }
    }
    return true;
}
项目:wso2-axis2    文件:SOAPMessageImpl.java   
/**
 * Removes all the AttachmentPart objects that have header entries that match the specified
 * headers. Note that the removed attachment could have headers in addition to those specified.
 *
 * @param headers - a MimeHeaders object containing the MIME headers for which to search
 * @since SAAJ 1.3
 */
public void removeAttachments(MimeHeaders headers) {
    Collection<AttachmentPart> newAttachmentParts = new ArrayList<AttachmentPart>();
    for (AttachmentPart attachmentPart : attachmentParts) {
        //Get all the headers
        for (Iterator iterator = headers.getAllHeaders(); iterator.hasNext();) {
            MimeHeader mimeHeader = (MimeHeader)iterator.next();
            String[] headerValues = attachmentPart.getMimeHeader(mimeHeader.getName());
            //if values for this header name, do not remove it
            if (headerValues.length != 0) {
                if (!(headerValues[0].equals(mimeHeader.getValue()))) {
                    newAttachmentParts.add(attachmentPart);
                }
            }
        }
    }
    attachmentParts.clear();
    this.attachmentParts = newAttachmentParts;
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testSendReceive_ISO88591_EncodedSOAPMessage() throws Exception {
    MimeHeaders mimeHeaders = new MimeHeaders();
    mimeHeaders.addHeader("Content-Type", "text/xml; charset=iso-8859-1");

    InputStream inputStream = TestUtils.getTestFile("soap-part-iso-8859-1.xml");
    SOAPMessage requestMessage = MessageFactory.newInstance().createMessage(mimeHeaders, inputStream);


    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(requestMessage, getAddress());
    assertFalse(response.getAttachments().hasNext());
    assertEquals(0, response.countAttachments());

    printSOAPMessage(requestMessage);
    String responseStr = printSOAPMessage(response);
    assertEquals("This is some text.Here are some special chars : \u00F6\u00C6\u00DA\u00AE\u00A4",
                 response.getSOAPBody().getElementsByTagName("something").item(0).getTextContent());
    assertTrue(responseStr.indexOf("echo") != -1);
    sCon.close();
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testCallMTOM() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();

    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", TestUtils.MTOM_TEST_MESSAGE_CONTENT_TYPE);
    InputStream in = TestUtils.getTestFile(TestUtils.MTOM_TEST_MESSAGE_FILE);
    SOAPMessage request = mf.createMessage(headers, in);
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();

    // Remove the headers since they have mustunderstand=1 
    envelope.getHeader().removeContents();
    // Change the name of the body content so that the request is routed to the echo service
    ((SOAPElement)envelope.getBody().getChildElements().next()).setElementQName(new QName("echo"));

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    sCon.close();

    SOAPPart soapPart = response.getSOAPPart();
    SOAPElement textElement =
            (SOAPElement)soapPart.getEnvelope().getElementsByTagName("text").item(0);
    AttachmentPart ap = response.getAttachment((SOAPElement)textElement.getChildNodes().item(0));
    assertNotNull(ap);
}
项目:wso2-axis2    文件:SOAPFaultDetailTest.java   
@Test
public void testDetails() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage smsg =
            mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
    SOAPBody body = smsg.getSOAPBody();
    //smsg.writeTo(System.out);
    SOAPFault fault = body.getFault();
    fault.addDetail();
    javax.xml.soap.Detail d = fault.getDetail();
    Iterator i = d.getDetailEntries();
    while (i.hasNext()) {
        DetailEntry entry = (DetailEntry)i.next();
        String name = entry.getElementName().getLocalName();
        if ("tickerSymbol".equals(name)) {
            assertEquals("the value of the tickerSymbol element didn't match",
                         "MACR", entry.getValue());
        } else if ("exceptionName".equals(name)) {
            assertEquals("the value of the exceptionName element didn't match",
                         "test.wsdl.faults.InvalidTickerFaultMessage", entry.getValue());
        } else {
            assertTrue("Expecting details element name of 'tickerSymbol' or " +
                    "'expceptionName' - I found :" + name, false);
        }
    }
}
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
public void _testEnvelopeWithLeadingComment() throws Exception {
    String soapMessageWithLeadingComment =
            "<?xml version='1.0' encoding='UTF-8'?>" +
                    "<!-- Comment -->" +
                    "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
                    "<env:Body><echo><arg0>Hello</arg0></echo></env:Body>" +
                    "</env:Envelope>";

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message =
            factory.createMessage(new MimeHeaders(),
                                  new ByteArrayInputStream(
                                          soapMessageWithLeadingComment.getBytes()));
    SOAPPart part = message.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    message.writeTo(System.out);
    assertTrue(envelope != null);
    assertTrue(envelope.getBody() != null);
}
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
@Validated @Test
    public void testEnvelopeWithCommentInEnvelope() throws Exception {

        String soapMessageWithLeadingComment =
                "<?xml version='1.0' encoding='UTF-8'?>\n" +
                        "<soapenv:Envelope  xmlns='http://somewhere.com/html'\n" +
                        "                   xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
                        "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
                        "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
                        "<!-- Comment -->" +
                        " <soapenv:Body>\n" +
                        "    <echo><arg0>Hello</arg0></echo>" +
//                "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
                        " </soapenv:Body>\n" +
                        "</soapenv:Envelope>";

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message =
                factory.createMessage(new MimeHeaders(),
                                      new ByteArrayInputStream(
                                              soapMessageWithLeadingComment.getBytes()));
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        assertTrue(envelope != null);
        assertTrue(envelope.getBody() != null);
    }
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
@Validated @Test
    public void testEnvelopeWithCommentInBody() throws Exception {

        String soapMessageWithLeadingComment =
                "<?xml version='1.0' encoding='UTF-8'?>\n" +
                        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
                        "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
                        "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
                        " <soapenv:Body>\n" +
                        "<!-- Comment -->" +
//                "    <echo><arg0>Hello</arg0></echo>" +
                        "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
                        " </soapenv:Body>\n" +
                        "</soapenv:Envelope>";

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message =
                factory.createMessage(new MimeHeaders(),
                                      new ByteArrayInputStream(
                                              soapMessageWithLeadingComment.getBytes()));
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        assertTrue(envelope != null);
        assertTrue(envelope.getBody() != null);
    }
项目:wso2-axis2    文件:MessageFactoryTest.java   
@Validated @Test
public void testNewInstane() {
    try {
        MessageFactory mf = MessageFactory.newInstance();
        assertNotNull(mf);
        ByteArrayOutputStream baos1 = new ByteArrayOutputStream();

        SOAPMessage msg1 = mf.createMessage();
        msg1.writeTo(baos1);

        MimeHeaders headers = new MimeHeaders();
        headers.addHeader("Content-Type", "text/xml");

    } catch (Exception e) {
        fail("Exception: " + e);
    }
}
项目:wso2-axis2    文件:PrefixesTest.java   
@Validated @Test
public void testAttribute() throws Exception {
    String soappacket =
            "<soapenv:Envelope xmlns:soapenv =\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                    "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
                    "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
                    "   <soapenv:Body>\n" +
                    "       <t:helloworld t:name=\"test\" xmlns:t='http://test.org/Test'>Hello</t:helloworld>\n" +
                    "   </soapenv:Body>\n" +
                    "</soapenv:Envelope>";

    SOAPMessage msg =
            MessageFactory.newInstance().createMessage(new MimeHeaders(),
                                                       new ByteArrayInputStream(
                                                               soappacket.getBytes()));
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    validateBody(body.getChildElements());
}
项目:carbon-qos    文件:SAAJMessageBuilderTest.java   
public void testMessageBuilingFromByteArray() throws Exception {

        SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
        SOAPEnvelope env = fac.createSOAPEnvelope();
        fac.createSOAPBody(env);
        env.getBody().addChild(fac.createOMElement("test", "http://t", "t"));
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        try {
            env.serialize(outStream);
            MessageFactory mf = MessageFactory.newInstance();
            mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(outStream.toByteArray()));
        } catch (Exception e) {
            e.printStackTrace();
            assertTrue(true);
        }
    }
项目:openjdk-icedtea7    文件:SOAPProviderArgumentBuilder.java   
@Override
protected Packet getResponse(Packet request, @Nullable SOAPMessage returnValue, WSDLPort port, WSBinding binding) {
    Packet response = super.getResponse(request, returnValue, port, binding);
    // Populate SOAPMessage's transport headers
    if (returnValue != null && response.supports(Packet.OUTBOUND_TRANSPORT_HEADERS)) {
        MimeHeaders hdrs = returnValue.getMimeHeaders();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Iterator i = hdrs.getAllHeaders();
        while(i.hasNext()) {
            MimeHeader header = (MimeHeader)i.next();
            if(header.getName().equalsIgnoreCase("SOAPAction"))
                // SAAJ sets this header automatically, but it interferes with the correct operation of JAX-WS.
                // so ignore this header.
                continue;

            List<String> list = headers.get(header.getName());
            if (list == null) {
                list = new ArrayList<String>();
                headers.put(header.getName(), list);
            }
            list.add(header.getValue());
        }
        response.put(Packet.OUTBOUND_TRANSPORT_HEADERS, headers);
    }
    return response;
}
项目:bandwidth-on-demand    文件:KisOnlineClient.java   
/**
 * Constructed SOAP Request Message:
 *
 * <pre>
 * &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://surfnet.nl/webservices/"&gt;
 *   &lt;soapenv:Header/&gt;
 *   &lt;soapenv:Body&gt;
 *     &lt;web:getKlanten/&gt;
 *   &lt;/soapenv:Body&gt;
 * &lt;/soapenv:Envelope&gt;
 * </pre>
 *
 * @throws SOAPException
 */
public static SOAPMessage createGetKlantenRequest(String username, String password) throws SOAPException {
  MessageFactory messageFactory = MessageFactory.newInstance();
  SOAPMessage soapMessage = messageFactory.createMessage();
  SOAPPart soapPart = soapMessage.getSOAPPart();

  // SOAP Envelope
  SOAPEnvelope envelope = soapPart.getEnvelope();
  envelope.addNamespaceDeclaration(KIS_NAMESPACE_PREFIX, KIS_NAMESPACE_URI);

  // SOAP Body
  SOAPBody soapBody = envelope.getBody();
  soapBody.addChildElement("getKlanten", KIS_NAMESPACE_PREFIX);

  String authorization = Base64.getEncoder().encodeToString((username + ":" + password).getBytes(Charset.forName("UTF-8")));
  MimeHeaders headers = soapMessage.getMimeHeaders();
  headers.addHeader("Authorization", "Basic " + authorization);
  headers.addHeader("SOAPAction", KIS_NAMESPACE_URI + "IgetKlant/getKlanten");

  soapMessage.saveChanges();

  return soapMessage;
}
项目:jentrata    文件:SoapMessageDataFormat.java   
/**
 * Converts a SOAPMessage into a org.wc3.Document
 *
 * Using a custom message header you can which SOAP Version the message is in
 *
 * @param exchange
 * @param stream
 * @return
 * @throws Exception
 */
@Override
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
    InputStream body = exchange.getContext().getTypeConverter().convertTo(InputStream.class,exchange.getIn().getBody());
    String soapVersion = exchange.getIn().getHeader(EbmsConstants.SOAP_VERSION, SOAPConstants.SOAP_1_2_PROTOCOL, String.class);
    MessageFactory messageFactory = MessageFactory.newInstance(soapVersion);
    MimeHeaders mimeHeaders = new MimeHeaders();
    mimeHeaders.addHeader(Exchange.CONTENT_TYPE, exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class));
    SOAPMessage message = messageFactory.createMessage(mimeHeaders, body);
    SOAPHeader soapHeader = message.getSOAPPart().getEnvelope().getHeader();

    if(message.countAttachments() > 0) {
        addAttachments(message, exchange);
    }

    return soapHeader.getOwnerDocument();
}
项目:HouseControl    文件:WemoControl.java   
private SOAPMessage createBinaryStateRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "urn:Belkin:service:basicevent:1";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("u", serverURI);

    SOAPBody soapBody = envelope.getBody();
    soapBody.addChildElement("GetBinaryState", "u");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", "\"urn:Belkin:service:basicevent:1#GetBinaryState\"");

    soapMessage.saveChanges();

    return soapMessage;
}
项目:HouseControl    文件:WemoControl.java   
private SOAPMessage createInsightParamsRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "urn:Belkin:service:insight:1";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("u", serverURI);

    SOAPBody soapBody = envelope.getBody();
    soapBody.addChildElement("GetInsightParams", "u");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", "\"urn:Belkin:service:insight:1#GetInsightParams\"");

    soapMessage.saveChanges();

    return soapMessage;
}
项目:onvifjava    文件:CameraDiscovery.java   
private void parseSoapResponseForUrls(byte[] data) {
//          System.out.println(new String(data));
            try {
                MessageFactory factory= MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
                final MimeHeaders headers = new MimeHeaders();
//              headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
                SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
                SOAPPart part=message.getSOAPPart();
                SOAPEnvelope env=part.getEnvelope();
                SOAPBody body=message.getSOAPBody();
                NodeList list=body.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2005/04/discovery", "XAddrs");
                int items=list.getLength();
                if(items<1)return;
                for (int i = 0; i < items; i++) {
                    Node n=list.item(i);
                    String raw=n.getTextContent();
                    //may contain several
                    String []addrArray=raw.split(" ");
                    for (String string : addrArray) {
                        URL url=new URL(string);
                        discovered.add(url);                        
                    }
                }
            } catch (Exception e) {
                System.out.println("Parse failed");
                e.printStackTrace();
            }

        }
项目:OpenJSharp    文件:MessageContextFactory.java   
/**
     * @deprecated http://java.net/jira/browse/JAX_WS-1077
     */
    @Deprecated
    public com.oracle.webservices.internal.api.message.MessageContext createContext(InputStream in, MimeHeaders headers) throws IOException {
        String contentType = getHeader(headers, "Content-Type");
        Packet packet = (Packet) createContext(in, contentType);
        packet.acceptableMimeTypes = getHeader(headers, "Accept");
        packet.soapAction = fixQuotesAroundSoapAction(getHeader(headers, "SOAPAction"));
//      packet.put(Packet.INBOUND_TRANSPORT_HEADERS, toMap(headers));
        return packet;
    }
项目:OpenJSharp    文件:MessageContextFactory.java   
static Map<String, List<String>> toMap(MimeHeaders headers) {
    HashMap<String, List<String>> map = new HashMap<String, List<String>>();
    for (Iterator<MimeHeader> i = headers.getAllHeaders(); i.hasNext();) {
        MimeHeader mh = i.next();
        List<String> values = map.get(mh.getName());
        if (values == null) {
            values = new ArrayList<String>();
            map.put(mh.getName(), values);
        }
        values.add(mh.getValue());
    }
    return map;
}
项目:OpenJSharp    文件:Message.java   
public static void addSOAPMimeHeaders(MimeHeaders mh, Map<String, List<String>> headers) {
    for(Map.Entry<String, List<String>> e : headers.entrySet()) {
        if (!e.getKey().equalsIgnoreCase("Content-Type")) {
            for(String value : e.getValue()) {
                mh.addHeader(e.getKey(), value);
            }
        }
    }
}
项目:OpenJSharp    文件:MimeHeadersUtil.java   
public static MimeHeaders copy(MimeHeaders headers) {
    MimeHeaders newHeaders = new MimeHeaders();
    Iterator eachHeader = headers.getAllHeaders();
    while (eachHeader.hasNext()) {
        MimeHeader currentHeader = (MimeHeader) eachHeader.next();

        newHeaders.addHeader(
            currentHeader.getName(),
            currentHeader.getValue());
    }
    return newHeaders;
}