當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeHeaders類代碼示例

本文整理匯總了Java中javax.xml.soap.MimeHeaders的典型用法代碼示例。如果您正苦於以下問題:Java MimeHeaders類的具體用法?Java MimeHeaders怎麽用?Java MimeHeaders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MimeHeaders類屬於javax.xml.soap包,在下文中一共展示了MimeHeaders類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSOAPRequestMessage

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:AgileTestingFramework,項目名稱:atf-toolbox-java,代碼行數:40,代碼來源:WebServiceAutomationManager.java

示例2: getResponse

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
@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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:SOAPProviderArgumentBuilder.java

示例3: getHeaders

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:22,代碼來源:AdapterUtils.java

示例4: create

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
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;
}
 
開發者ID:hill-daniel,項目名稱:soap-wrapper-lambda,代碼行數:21,代碼來源:ExampleSoapMessage.java

示例5: addHeaders

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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);
                }
            }
        }
    }
}
 
開發者ID:cecid,項目名稱:hermes,代碼行數:30,代碼來源:Headers.java

示例6: printMessage

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
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();
    }
}
 
開發者ID:jembi,項目名稱:openxds,代碼行數:17,代碼來源:SoapRequestBean.java

示例7: parseMessage

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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);
  }
}
 
開發者ID:e-gov,項目名稱:AJ,代碼行數:25,代碼來源:SoapUtil.java

示例8: checkContentType

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
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");
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:17,代碼來源:TestHandler.java

示例9: handleOutbound

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
@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;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:20,代碼來源:ClientMimeHandler.java

示例10: handleInbound

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
@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;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:26,代碼來源:ClientMimeHandler.java

示例11: handleInbound

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
@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;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:26,代碼來源:ServerMimeHandler.java

示例12: handleOutbound

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
@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;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:23,代碼來源:ServerMimeHandler.java

示例13: testSoap12Request

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
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();
		
	}
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:24,代碼來源:SOAPBindingProviderTests.java

示例14: matches

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:30,代碼來源:AttachmentPartImpl.java

示例15: removeAttachments

import javax.xml.soap.MimeHeaders; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:26,代碼來源:SOAPMessageImpl.java


注:本文中的javax.xml.soap.MimeHeaders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。