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


Java SOAPFault類代碼示例

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


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

示例1: callWebService

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public void callWebService(String iccid, String businessValue) throws SOAPException, IOException, XWSSecurityException, Exception {
    SOAPMessage request = createTerminalRequest(iccid, businessValue);
    request = secureMessage(request);

    // TODO
    logger.info("Edit Terminal Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Edit Terminal Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
    }
}
 
開發者ID:booleguo,項目名稱:sam-elle,代碼行數:26,代碼來源:EditTerminalClient.java

示例2: SOAP12Fault

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
SOAP12Fault(SOAPFault fault) {
    code = new CodeType(fault.getFaultCodeAsQName());
    try {
        fillFaultSubCodes(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }

    reason = new ReasonType(fault.getFaultString());
    role = fault.getFaultRole();
    node = fault.getFaultNode();
    if (fault.getDetail() != null) {
        detail = new DetailType();
        Iterator iter = fault.getDetail().getDetailEntries();
        while(iter.hasNext()){
            Element fd = (Element)iter.next();
            detail.getDetails().add(fd);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:SOAP12Fault.java

示例3: callWebService

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public String callWebService(String msisdn) throws SOAPException, IOException, XWSSecurityException, GetTermalIccidException {
    SOAPMessage request = createTerminalRequest(msisdn);
    request = secureMessage(request);

    // TODO
    logger.info("Get Terminals by msisdn Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Get Terminals by msisdn Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        return writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
        throw new GetTermalIccidException(fault.getFaultCode() + "," + fault.getFaultString());
    }
}
 
開發者ID:booleguo,項目名稱:sam-elle,代碼行數:27,代碼來源:GetTerminalsByMsisdnClient.java

示例4: _testQuick

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public void _testQuick() throws Exception {
    MessageFactory msgfactory = MessageFactory.newInstance();
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPMessage outputmsg = msgfactory.createMessage();
    String valueCode = "faultcode";
    String valueString = "faultString";
    SOAPFault fault = outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
    fault.setFaultCode(valueCode);
    fault.setFaultString(valueString);
    Detail detail = fault.addDetail();
    detail.addDetailEntry(factory.createName("Hello"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (outputmsg.saveRequired()) {
        outputmsg.saveChanges();
    }
    outputmsg.writeTo(baos);
    String xml = new String(baos.toByteArray());
    assertTrue(xml.indexOf("Hello") != -1);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:20,代碼來源:SOAPFaultTest.java

示例5: getProtocolException

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:SOAP11Fault.java

示例6: fillFaultSubCodes

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
/**
 * Adds Fault subcodes from {@link SOAPFault} to {@link #code}
 */
private void fillFaultSubCodes(SOAPFault fault) throws SOAPException {
    Iterator subcodes = fault.getFaultSubcodes();
    SubcodeType firstSct = null;
    while(subcodes.hasNext()){
        QName subcode = (QName)subcodes.next();
        if(firstSct == null){
            firstSct = new SubcodeType(subcode);
            code.setSubcode(firstSct);
            continue;
        }
        SubcodeType nextSct = new SubcodeType(subcode);
        firstSct.setSubcode(nextSct);
        firstSct = nextSct;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:SOAP12Fault.java

示例7: addFault

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
@Override
public SOAPFault addFault() throws SOAPException {
    if (hasFault()) {
        log.severe("SAAJ0110.impl.fault.already.exists");
        throw new SOAPExceptionImpl("Error: Fault already exists");
    }

    fault = createFaultElement();

    addNode(fault);

    fault.setFaultCode(getDefaultFaultCode());
    fault.setFaultString("Fault string, and possibly fault code, not set");

    return fault;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:BodyImpl.java

示例8: addFault

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
/**
 * Adds a SOAP fault to the SOAP message of this response.
 * 
 * @param code the fault code.
 * @param actor the fault actor.
 * @param desc the fault description.
 * @return the SOAP fault which has been added to the SOAP message. null if
 *         there is no SOAP message in this response or the fault has
 *         already been added.
 * @throws SOAPException a SOAP error occurred when adding the the fault.
 */
public SOAPFault addFault(String code, String actor, String desc)
        throws SOAPException {
    SOAPMessage msg = getMessage();
    if (msg != null) {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            SOAPFault fault = body.addFault();
            if (code != null) {
                fault.setFaultCode(env.getElementName().getPrefix() + ":"
                        + code);
            }
            if (actor != null) {
                fault.setFaultActor(actor);
            }
            if (desc != null) {
                fault.setFaultString(desc);
            }
            return fault;
        }
    }
    return null;
}
 
開發者ID:cecid,項目名稱:hermes,代碼行數:35,代碼來源:SOAPResponse.java

示例9: invoke

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
@Override
public DOMSource invoke(DOMSource request) {
    try {
        return invokeAllowingFaults(request);
    } catch (FaultMessage faultMessage) {
        try {
            SOAPFactory factory = SOAPFactory.newInstance();
            SOAPFault soapFault = factory.createFault();
            soapFault.setFaultCode(SOAP11_FAULTCODE_SERVER);           // todo here is a constant until we have a mechanism to determine the correct value (client / server)
            soapFault.setFaultString(faultMessage.getMessage());
            Detail detail = soapFault.addDetail();
            serializeFaultMessage(detail, faultMessage);
            // fault actor?
            // stack trace of the outer exception (FaultMessage) is unimportant, because it is always created at one place
            // todo consider providing stack trace of the inner exception
            //Detail detail = soapFault.addDetail();
            //detail.setTextContent(getStackTraceAsString(faultMessage));
            throw new SOAPFaultException(soapFault);
        } catch (SOAPException e) {
            throw new RuntimeException("SOAP Exception: " + e.getMessage(), e);
        }
    }
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:24,代碼來源:ModelWebServiceRaw.java

示例10: invoke

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public SOAPMessage invoke(SOAPMessage requestSoapMessage)
   {
      SOAPFault theSOAPFault;
      try {
         theSOAPFault = SOAPFactory.newInstance().createFault();
         Detail soapFaultDetail = theSOAPFault.addDetail();
         SOAPElement myFaultElement = soapFaultDetail.addChildElement(new QName("http://www.my-company.it/ws/my-test", "MyWSException"));
         SOAPElement myMessageElement = myFaultElement.addChildElement(new QName("http://www.my-company.it/ws/my-test", "message"));
//         myMessageElement.setNodeValue("This is a faked error"); //wrong: myMessageElement is not a text node
         myMessageElement.setValue("This is a faked error"); //right: this creates a text node and gives it a text value
      } catch (SOAPException se) {
         se.printStackTrace();
         throw new RuntimeException("Something unexpected happened!");
      }
      throw new SOAPFaultException(theSOAPFault);
   }
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:17,代碼來源:ProviderImpl.java

示例11: handleOutbound

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
protected boolean handleOutbound(final SOAPMessageContext msgContext)
{
   try
   {
      SOAPFault fault = null;
      MessageFactory factory = MessageFactory.newInstance(); 
      SOAPMessage resMessage = factory.createMessage();
      fault = resMessage.getSOAPBody().addFault();
      fault.setFaultString("this is an exception thrown by client outbound");
      throw new SOAPFaultException(fault);
   }
   catch (SOAPException e)
   {
      //ignore
   }
   return true;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:18,代碼來源:ClientSOAPHandler.java

示例12: throwSoapFaultException

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public void throwSoapFaultException()
{
   // This should be thrown as-is
   try
   {
      SOAPFactory factory = SOAPFactory.newInstance();
      SOAPFault fault = factory.createFault("this is a fault string!", SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
      fault.setFaultActor("mr.actor");
      fault.addDetail().addChildElement("test");
      throw new SOAPFaultException(fault);
   }
   catch (SOAPException s)
   {
      throw new RuntimeException(s);
   }
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:17,代碼來源:EndpointImpl.java

示例13: throwSoapFaultException

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public void throwSoapFaultException()
{
   try
   {
      MessageContext ctx = context.getMessageContext();
      ctx.put(MessageContext.HTTP_RESPONSE_CODE, 400);
      
      SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
      SOAPFault fault = factory.createFault();
      fault.addFaultReasonText("this is a fault string!", Locale.ITALIAN);
      fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
      fault.setFaultActor("mr.actor");
      fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "AnException"));
      fault.addDetail().addChildElement("test");
      throw new SOAPFaultException(fault);
   }
   catch (Exception s)
   {
      throw new RuntimeException(s);
   }
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:22,代碼來源:JBWS3945EndpointImpl.java

示例14: throwSoapFaultException

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
public void throwSoapFaultException()
{
   // This should be thrown as-is
   try
   {
      SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
      SOAPFault fault = factory.createFault();
      fault.addFaultReasonText("this is a fault string!", Locale.ITALIAN);
      fault.setFaultCode(SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
      fault.setFaultActor("mr.actor");
      fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
      fault.addDetail().addChildElement("test");
      throw new SOAPFaultException(fault);
   }
   catch (SOAPException s)
   {
      throw new RuntimeException(s);
   }
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:20,代碼來源:SOAP12EndpointImpl.java

示例15: testIllegalMessageAccess

import javax.xml.soap.SOAPFault; //導入依賴的package包/類
@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception
{
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();

   String reqEnv =
      "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
      " <env:Header/>" +
      " <env:Body>" +
      "  <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" +
      "   <String_1>Hello</String_1>" +
      "  </ns1:noWebMethod>" +
      " </env:Body>" +
      "</env:Envelope>";
   SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));

   URL epURL = new URL(baseURL + "/TestService");
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   SOAPFault soapFault = resMsg.getSOAPBody().getFault();
   assertNotNull("Expected SOAPFault", soapFault);

   String faultString = soapFault.getFaultString();
   assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:27,代碼來源:WebMethodTestCase.java


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