javax.xml.soap.SOAPFactory Java Examples

The following examples show how to use javax.xml.soap.SOAPFactory. 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: ReferenceParametersAddingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(SOAPMessageContext context) {
    // we are interested only in outbound messages here
    if (!(Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        return true;
    }
    if (params == null) {
        return true;
    }
    try {
        SOAPFactory factory = SOAPFactory.newInstance();
        for (Object o : params.getAny()) {
            SOAPElement elm = factory.createElement((Element)o);
            context.getMessage().getSOAPHeader()
                    .addChildElement(SOAPFactory.newInstance().createElement(elm));
        }
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
    return true;
}
 
Example #2
Source File: SAAJMetaFactoryImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected  SOAPFactory newSOAPFactory(String protocol)
    throws SOAPException {
    if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl();
    } else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPFactory1_2Impl();
    } else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPFactoryDynamicImpl();
    } else {
        log.log(
            Level.SEVERE,
            "SAAJ0569.soap.unknown.protocol",
            new Object[] {protocol, "SOAPFactory"});
        throw new SOAPException("Unknown Protocol: " + protocol +
                                    "  specified for creating SOAPFactory");
    }
}
 
Example #3
Source File: SAAJMetaFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected  SOAPFactory newSOAPFactory(String protocol)
    throws SOAPException {
    if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl();
    } else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPFactory1_2Impl();
    } else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPFactoryDynamicImpl();
    } else {
        log.log(
            Level.SEVERE,
            "SAAJ0569.soap.unknown.protocol",
            new Object[] {protocol, "SOAPFactory"});
        throw new SOAPException("Unknown Protocol: " + protocol +
                                    "  specified for creating SOAPFactory");
    }
}
 
Example #4
Source File: JaxWsHandlerTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests
 * {@link JaxWsHandler#setHeaderChildString(BindingProvider, String, String, String, String)} when
 * headers exist but the parent header name passed does not match any of them.
 */
@Test
public void testSetHeaderChildString_fail_noMatchingParent() throws Exception {
  String parentNamespace = "parentNamespace";
  String parentName = "parentName";

  when(mockSoapClient.getBinding()).thenReturn(mockBinding);
  when(mockBinding.getHandlerChain()).thenReturn(handlerChain);

  // Add the parent header.
  SOAPFactory soapFactory = SOAPFactory.newInstance();
  SOAPElement parentHeader = soapFactory.createElement(parentName, null, parentNamespace);
  jaxWsHandler.setHeader(mockSoapClient, parentNamespace, parentName, parentHeader);

  // Add the child header but specify a non-existent parent header name.
  thrown.expect(NullPointerException.class);
  jaxWsHandler.setHeaderChildString(mockSoapClient, parentName + "_nonexistent", "childNamespace",
      "childName", "childValue");
}
 
Example #5
Source File: ProviderRPCClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSWA() throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();

    QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();
    ap1.setContent("Attachment content", "text/plain");
    msg.addAttachmentPart(ap1);
    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();

    SOAPConnection con = conFac.createConnection();
    URL endpoint = new URL("http://localhost:" + PORT
                           + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
    assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
    assertEquals(2, response.countAttachments());
}
 
Example #6
Source File: AdManagerJaxWsHeaderHandler.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a SOAP header object ready to be attached to a JAX-WS client.
 *
 * @param headerData a map of SOAP header element names to values
 * @param adManagerServiceDescriptor the descriptor of which service's headers are being created
 * @return a SOAP header object
 */
private SOAPElement constructSoapHeader(
    Map<String, Object> headerData, AdManagerServiceDescriptor adManagerServiceDescriptor) {
  String requestHeaderNamespace =
      adManagerApiConfiguration.getNamespacePrefix()
          + "/"
          + adManagerServiceDescriptor.getVersion();

  try {
    SOAPFactory soapFactory = SOAPFactory.newInstance();
    SOAPElement requestHeader =
        soapFactory.createElement(REQUEST_HEADER_LOCAL_PART, "ns1", requestHeaderNamespace);
    for (String headerElementName : headerData.keySet()) {
      if (headerData.get(headerElementName) != null) {
        SOAPElement newElement =
            requestHeader.addChildElement(headerElementName, "ns1", requestHeaderNamespace);
        newElement.addTextNode(headerData.get(headerElementName).toString());
      }
    }
    return requestHeader;
  } catch (SOAPException e) {
    throw new ServiceException("Unexpected exception.", e);
  }
}
 
Example #7
Source File: TestSOAPHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SOAPFaultException createSOAPFaultExceptionWithDetail(String faultString)
    throws SOAPException {

    SOAPFault fault = SOAPFactory.newInstance().createFault();

    QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
                    "Server");
    SAAJUtils.setFaultCode(fault, faultName);
    fault.setFaultActor("http://gizmos.com/orders");
    fault.setFaultString(faultString);

    Detail detail = fault.addDetail();

    QName entryName = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry = detail.addDetailEntry(entryName);
    entry.addTextNode("Quantity element does not have a value");

    QName entryName2 = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry2 = detail.addDetailEntry(entryName2);
    entry2.addTextNode("Incomplete address: no zip code");

    return new SOAPFaultException(fault);
}
 
Example #8
Source File: EchoServiceImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SOAPFaultException wrapToSoapFault(Exception ex) throws Exception {
    SOAPFactory fac = null;
    try {
        fac = SOAPFactory.newInstance();
        String message = ex.getMessage();
        SOAPFault sf = fac.createFault(message, new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE,
                                                          "Server"));
        sf.setFaultString("TestSOAPFaultException");
        // add detail makes CXF goes in a infinite loop
        sf.addDetail().addDetailEntry(new QName("urn:echo", "entry")).addTextNode("SOAPFaultException");

        return new SOAPFaultException(sf);
    } catch (Exception e2) {

        throw e2;
    }
}
 
Example #9
Source File: SAAJMetaFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected  SOAPFactory newSOAPFactory(String protocol)
    throws SOAPException {
    if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl();
    } else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPFactory1_2Impl();
    } else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPFactoryDynamicImpl();
    } else {
        log.log(
            Level.SEVERE,
            "SAAJ0569.soap.unknown.protocol",
            new Object[] {protocol, "SOAPFactory"});
        throw new SOAPException("Unknown Protocol: " + protocol +
                                    "  specified for creating SOAPFactory");
    }
}
 
Example #10
Source File: DocLitBareCodeFirstServiceImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public GreetMeResponse greetMe(GreetMeRequest gmr) {
    if ("fault".equals(gmr.getName())) {
        try {
            SOAPFactory factory = SOAPFactory.newInstance();
            SOAPFault fault = factory.createFault("this is a fault string!",
                                                  new QName("http://foo", "FooCode"));
            fault.setFaultActor("mr.actor");
            fault.addDetail().addChildElement("test").addTextNode("TestText");
            throw new SOAPFaultException(fault);
        } catch (SOAPException ex) {
            throw new WebServiceException(ex);
        }
    } else if ("emptyfault".equals(gmr.getName())) {
        throw new RuntimeException("Empty!");
    }

    GreetMeResponse resp = new GreetMeResponse();
    resp.setName(gmr.getName());
    return resp;
}
 
Example #11
Source File: SAAJMetaFactoryImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected  SOAPFactory newSOAPFactory(String protocol)
    throws SOAPException {
    if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl();
    } else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPFactory1_2Impl();
    } else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
        return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPFactoryDynamicImpl();
    } else {
        log.log(
            Level.SEVERE,
            "SAAJ0569.soap.unknown.protocol",
            new Object[] {protocol, "SOAPFactory"});
        throw new SOAPException("Unknown Protocol: " + protocol +
                                    "  specified for creating SOAPFactory");
    }
}
 
Example #12
Source File: SOAPUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SOAPFaultException newSOAPFaultException(String reasonText, Throwable cause) {
   try {
      SOAPFactory factory = SOAPFactory.newInstance();
      SOAPFault soapFault = factory.createFault();
      soapFault.setFaultString(reasonText);
      SOAPFaultException except = new SOAPFaultException(soapFault);
      except.initCause(cause);
      return except;
   } catch (SOAPException var5) {
      throw new IllegalArgumentException(var5);
   }
}
 
Example #13
Source File: WsaTubeHelper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #14
Source File: JaxWsHandlerTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Tests
 * {@link JaxWsHandler#setHeaderChildString(BindingProvider, String, String, String, String)} when
 * given valid inputs.
 */
@Test
public void testSetHeaderChildString() throws Exception {
  String parentNamespace = "parentNamespace";
  String parentName = "parentName";

  when(mockSoapClient.getBinding()).thenReturn(mockBinding);
  when(mockBinding.getHandlerChain()).thenReturn(handlerChain);

  // Add the parent header.
  SOAPFactory soapFactory = SOAPFactory.newInstance();
  SOAPElement parentHeader = soapFactory.createElement(parentName, null, parentNamespace);
  jaxWsHandler.setHeader(mockSoapClient, parentNamespace, parentName, parentHeader);

  // Add the child header.
  String childNamespace = "childNamespace";
  String childName = "childName";
  String childValue = "foo";
  jaxWsHandler.setHeaderChildString(mockSoapClient, parentName, childNamespace, childName,
      childValue);
  SOAPElement parentHeaderFromHandler =
      (SOAPElement) jaxWsHandler.getHeader(mockSoapClient, parentName);

  // Retrieve the added child and assert its attributes are correct.
  SOAPElement childHeaderFromHandler = (SOAPElement) parentHeaderFromHandler.getFirstChild();

  assertEquals("Child name incorrect", childName, childHeaderFromHandler.getNodeName());
  assertEquals("Child namespace incorrect", childNamespace,
      childHeaderFromHandler.getNamespaceURI());
  assertEquals("Child value incorrect", childValue, childHeaderFromHandler.getTextContent());
}
 
Example #15
Source File: TreasuryXTeeServiceImpl.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 #16
Source File: SOAPUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SOAPFaultException newSOAPFaultException(String reasonText, Throwable cause) {
   try {
      SOAPFactory factory = SOAPFactory.newInstance();
      SOAPFault soapFault = factory.createFault();
      soapFault.setFaultString(reasonText);
      SOAPFaultException except = new SOAPFaultException(soapFault);
      except.initCause(cause);
      return except;
   } catch (SOAPException var5) {
      throw new IllegalArgumentException(var5);
   }
}
 
Example #17
Source File: WsaTubeHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #18
Source File: WsaTubeHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #19
Source File: WsaTubeHelper.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #20
Source File: WsaTubeHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #21
Source File: SOAPBindingImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public SOAPFactory getSOAPFactory() {
    if (this.soapBinding instanceof SoapBindingInfo) {
        SoapBindingInfo bindingInfo = (SoapBindingInfo) this.soapBinding;
        try {
            return SAAJFactoryResolver.createSOAPFactory(bindingInfo.getSoapVersion());
        } catch (SOAPException e) {
            throw new WebServiceException(BUNDLE.getString("SAAJ_FACTORY_ERR"), e);
        }
    }
    return null;
}
 
Example #22
Source File: WsaTubeHelper.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #23
Source File: WsaTubeHelper.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #24
Source File: WsaTubeHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #25
Source File: WsaTubeHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #26
Source File: TestMustUnderstandHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean handleMessage(SOAPMessageContext ctx) {

        boolean continueProcessing = true;

        try {
            Object b = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            boolean outbound = (Boolean)b;
            SOAPMessage msg = ctx.getMessage();
            if (isServerSideHandler()) {
                if (outbound) {
                    QName qname = new QName("http://cxf.apache.org/mu", "MU");
                    SOAPPart soapPart = msg.getSOAPPart();
                    SOAPEnvelope envelope = soapPart.getEnvelope();
                    SOAPHeader header = envelope.getHeader();
                    if (header == null) {
                        header = envelope.addHeader();
                    }


                    SOAPHeaderElement headerElement
                        = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI()));

                    // QName soapMustUnderstand = new QName("http://schemas.xmlsoap.org/soap/envelope/",
                    // "mustUnderstand");
                    Name name = SOAPFactory.newInstance()
                        .createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
                    headerElement.addAttribute(name, "1");
                } else {
                    getHandlerInfoList(ctx).add(getHandlerId());
                }
            }
        } catch (SOAPException e) {
            e.printStackTrace();
        }
        return continueProcessing;
    }
 
Example #27
Source File: WsaTubeHelper.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #28
Source File: WsaTubeHelper.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #29
Source File: WsaTubeHelper.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
    QName name = e.getProblemHeader();
    QName subsubcode = e.getSubsubcode();
    QName subcode = av.invalidMapTag;
    String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getInvalidMapDetail(name, fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #30
Source File: WsaTubeHelper.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}