コード例 #1
0
  public void handleMessage(SoapMessage message) {
    if (getInvoker(message).getProtocolHandlers().isEmpty()) {
      return;
    }

    if (getInvoker(message).isOutbound()) {
      if (!chainAlreadyContainsSAAJ(message)) {
        SAAJ_OUT.handleMessage(message);
      }
      message.getInterceptorChain().add(ending);
    } else {
      boolean isFault = handleMessageInternal(message);
      SOAPMessage msg = message.getContent(SOAPMessage.class);
      if (msg != null) {
        XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(msg);
        message.setContent(XMLStreamReader.class, xmlReader);
        // replace headers
        try {
          SAAJInInterceptor.replaceHeaders(msg, message);
        } catch (SOAPException e) {
          e.printStackTrace();
        }
      }
      if (isFault) {
        Endpoint ep = message.getExchange().get(Endpoint.class);
        message.getInterceptorChain().abort();
        if (ep.getInFaultObserver() != null) {
          ep.getInFaultObserver().onMessage(message);
        }
      }
    }
  }
コード例 #2
0
ファイル: EchoImpl.java プロジェクト: julienfromentc/jaxws
  private SOAPFaultException createSOAPFaultException() {
    try {
      String namespace = "http://example.com/auctiontraq/schemas/doclit";
      SOAPFactory soapFactory = SOAPFactory.newInstance();
      Name name = soapFactory.createName("MySOAPFault", "ns0", namespace);
      Detail detail = soapFactory.createDetail();
      DetailEntry entry = detail.addDetailEntry(name);
      entry.addNamespaceDeclaration("data", namespace);
      Name attrName1 = soapFactory.createName("myAttr", "data", namespace);
      entry.addAttribute(attrName1, "myvalue");
      SOAPElement child = entry.addChildElement("message");
      child.addTextNode("Server Exception");

      Name name2 = soapFactory.createName("ExtraInformation", "ns0", namespace);
      DetailEntry entry2 = detail.addDetailEntry(name2);

      SOAPElement child2 = entry2.addChildElement("Reason");
      child2.addTextNode("Address Not Found");

      QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "server");
      SOAPFault sf = soapFactory.createFault("SOAP Fault Exception:Address Not Found", qname);
      org.w3c.dom.Node n = sf.getOwnerDocument().importNode(detail, true);
      sf.appendChild(n);
      return new SOAPFaultException(sf);
      // printDetail(detail);
      // return new SOAPFaultException(qname,
      //       "SOAP Fault Exception:Address Not Found", null, detail);

    } catch (SOAPException e) {
      e.printStackTrace();
      // QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "client");
      throw new WebServiceException("Exception While Creating SOAP Fault Exception", e);
    }
  }
コード例 #3
0
ファイル: SOAPClient.java プロジェクト: Saxintosh/SOAPClient
  public STElement call() throws IOException {
    try {
      soapRequest.saveChanges();
      if (debug) {
        System.out.print("********* REQUEST:");
        Element e = new DOMReader().read(soapRequest.getSOAPPart()).getRootElement();
        writer.write(e);
        System.out.println();
        System.out.println("------------------");
      }

      soapResponse = conn.call(soapRequest, wsdlURL);

      if (debug) {
        System.out.print("********* RESPONSE:");
        Element e = new DOMReader().read(soapResponse.getSOAPPart()).getRootElement();
        writer.write(e);
        System.out.println();
        System.out.println("------------------");
      }

      SOAPPart sp = soapResponse.getSOAPPart();
      SOAPEnvelope env = sp.getEnvelope();
      return new STElement(env.getBody());
    } catch (SOAPException e) {
      e.printStackTrace();
      return null;
    }
  }
コード例 #4
0
  /** Adds an "Access" element to the SOAP header */
  public boolean handleRequest(MessageContext msgct) {
    if (msgct instanceof SOAPMessageContext) {
      SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
      try {
        SOAPMessage msg = smsgct.getMessage();
        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
        SOAPHeader header = msg.getSOAPHeader();

        if (header == null) header = envelope.addHeader(); // add an header if non exists

        SOAPHeaderElement accessElement =
            header.addHeaderElement(
                envelope.createName(
                    "Access", "ns0", "http://www.ipd.uni-karlsruhe.de/jplag/types"));
        SOAPElement usernameelem = accessElement.addChildElement("username");
        usernameelem.addTextNode(username);
        SOAPElement passwordelem = accessElement.addChildElement("password");
        passwordelem.addTextNode(password);
        SOAPElement compatelem = accessElement.addChildElement("compatLevel");
        compatelem.addTextNode(compatibilityLevel + "");
      } catch (SOAPException x) {
        System.out.println("Unable to create access SOAP header!");
        x.printStackTrace();
      }
    }
    return true;
  }
コード例 #5
0
ファイル: SOAPClient.java プロジェクト: Saxintosh/SOAPClient
 public void addNamespace(String prefix, String name) {
   try {
     SOAPPart sp = soapRequest.getSOAPPart();
     SOAPEnvelope env = sp.getEnvelope();
     env.addNamespaceDeclaration(prefix, name);
   } catch (SOAPException e) {
     e.printStackTrace();
   }
 }
コード例 #6
0
ファイル: MtomTest.java プロジェクト: julienfromentc/jaxws
 static {
   b.setBinary1(
       "fkldhafkdahfkdhfkhasdkfhldashfi9pweqryiweqyriqelhfklasdhfkldashflksdah".getBytes());
   b.setBinary2(
       "epriepireroerupequreopruopweuqrowequrpoweqrupweqrweqrweuqrweqrwerwerer".getBytes());
   try {
     messageFactory = MessageFactory.newInstance();
   } catch (SOAPException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
  private Object parseMessage() {
    // Consume SOAP message, if any
    // TODO: Add a SOAP handler in Parser.java
    if (soapAction != null) {
      try {
        MimeHeaders mime_headers = new MimeHeaders();

        for (Object k : headers.getIds()) {
          if (k instanceof String) {
            String name = (String) k;
            String value = Context.toString(ScriptableObject.getProperty(headers, name));

            mime_headers.addHeader(name, value);
          }
        }

        return MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL)
            .createMessage(mime_headers, request.getInputStream());
      } catch (IOException ex) {
        throw new ESXXException("Unable to read SOAP message stream: " + ex.getMessage());
      } catch (SOAPException ex) {
        throw new ESXXException(400 /* Bad Request */, "Invalid SOAP message: " + ex.getMessage());
      } finally {
        try {
          request.getInputStream().close();
        } catch (Exception ignored) {
        }
      }
    } else if (contentType != null && contentLength > 0) {
      try {
        ESXX esxx = ESXX.getInstance();
        return esxx.parseStream(
            contentType,
            request.getInputStream(),
            URI.create("urn:x-esxx:incoming-request-entity"),
            null,
            new java.io.PrintWriter(request.getErrorWriter()),
            Context.getCurrentContext(),
            this);
      } catch (Exception ex) {
        throw new ESXXException(
            400 /* Bad Request */, "Unable to parse request entity: " + ex.getMessage(), ex);
      } finally {
        try {
          request.getInputStream().close();
        } catch (Exception ignored) {
        }
      }
    } else {
      // Return a dummy object
      return Context.getCurrentContext().newObject(this);
    }
  }
コード例 #8
0
ファイル: ElementImpl.java プロジェクト: asoldano/saaj-impl
 public void setValue(String value) {
   Node valueNode = getValueNodeStrict();
   if (valueNode != null) {
     valueNode.setNodeValue(value);
   } else {
     try {
       addTextNode(value);
     } catch (SOAPException e) {
       throw new RuntimeException(e.getMessage());
     }
   }
 }
コード例 #9
0
 private XMLStreamReader createXMLStreamReaderFromSOAPMessage(SOAPMessage soapMessage) {
   // responseMsg.setContent(SOAPMessage.class, soapMessage);
   XMLStreamReader xmlReader = null;
   try {
     DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
     xmlReader = StaxUtils.createXMLStreamReader(bodySource);
     xmlReader.nextTag();
     xmlReader.nextTag(); // move past body tag
   } catch (SOAPException e) {
     e.printStackTrace();
   } catch (XMLStreamException e) {
     e.printStackTrace();
   }
   return xmlReader;
 }
コード例 #10
0
 private SOAPBody getSOAPBody(String request)
     throws UnsupportedEncodingException, SoapExceptionClient, IOException {
   SOAPMessage soapMessage = null;
   SOAPBody soapBody = null;
   try {
     MessageFactory factory = MessageFactory.newInstance();
     soapMessage =
         factory.createMessage(
             new MimeHeaders(), new ByteArrayInputStream(request.getBytes("UTF-8")));
     soapBody = soapMessage.getSOAPBody();
   } catch (SOAPException e) {
     throw new SoapExceptionClient(
         e.getLocalizedMessage() + " Cause: " + e.getCause().toString(), e);
   }
   return soapBody;
 }
コード例 #11
0
  @Override
  public void run() {
    //		new AttachmentHandler(this.message).printInformation();
    try {
      SOAPHeader header = this.message.getSOAPHeader();
      MetaInformation meta = new MetaInformation(header);
      meta.store();

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      this.message.writeTo(os);
      Logger.getLogger(ComponentConfig.COMPONENT_NAME)
          .debug(os.toString().replace("\n", "\\n") + "'");

      ResponseQueueHandler.newInstance().addLast(this.ipp);
    } catch (IOException e) {
      Logger.getLogger(ComponentConfig.COMPONENT_NAME).error(e.getLocalizedMessage());
    } catch (SOAPException e) {
      Logger.getLogger(ComponentConfig.COMPONENT_NAME).error(e.getLocalizedMessage());
    }
  }
コード例 #12
0
ファイル: test.java プロジェクト: d4m4g1c/Social-Intelligence
 public static void main(String[] args) {
   new LinkedHashMap() {
     @Override
     protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
       // TODO Auto-generated method stub
       return super.removeEldestEntry(eldest);
     }
   };
   for (int i = 33; i < 34; i++) {
     try {
       Neolane4J myNeolane = Neolane4J.getInstance();
       myNeolane.select("ecp", "results", new String[] {"id", "source", "datetime", "link"});
     } catch (SOAPException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
コード例 #13
0
ファイル: QueryClient.java プロジェクト: aldaris/opensso
  /**
   * Returns SAMLv2 <code>Response</code>. SAMLv2 request is sent enclosed in the body of a SOAP
   * Message to a SOAP endpoint. Prior to sending the request query, attributes required for
   * completeness of the SAMLv2 Request will be set (eg. Issuer) if not already set. Message will be
   * signed if signing is enabled. SAMLv2 Query Request will be enclosed in the SOAP Body to create
   * a SOAP message to send to the server.
   *
   * @param request the SAMLv2 <code>RequestAbstract</code> object.
   * @param pepEntityID entity identifier of the hosted query requester.
   * @param pdpEntityID entity identifier of the remote server.
   * @return SAMLv2 <code>Response</code> received from the Query Responder.
   * @throws SAML2Exception if there is an error processing the query.
   */
  public static Response processXACMLQuery(
      RequestAbstract request, String pepEntityID, String pdpEntityID) throws SAML2Exception {
    String classMethod = "QueryClient:processXACMLQuery";
    String realm = "/";
    Response samlResponse = null;
    Response response = null;
    // retreive pepEntityID metadata
    if (pepEntityID == null || pepEntityID.length() == 0) {
      debug.error(classMethod + "PEP Identifier is null");
      String[] data = {pepEntityID};
      LogUtil.error(Level.INFO, LogUtil.INVALID_PEP_ID, data);
      throw new SAML2Exception(SAML2SDKUtils.bundle.getString("nullPEP"));
    }
    // retreive pdpEntityID metadata
    if (pdpEntityID == null || pdpEntityID.length() == 0) {
      debug.error(classMethod + "PDP Identifier is null");
      String[] data = {pdpEntityID};
      LogUtil.error(Level.INFO, LogUtil.INVALID_PDP_ID, data);
      throw new SAML2Exception(SAML2SDKUtils.bundle.getString("nullPDP"));
    }

    if (request != null) {
      // set properties in the request.
      XACMLAuthzDecisionQuery xacmlQuery = (XACMLAuthzDecisionQuery) request;
      if (xacmlQuery != null) {
        // set Issuer
        Issuer issuer = createIssuer(pepEntityID);
        xacmlQuery.setIssuer(issuer);
        // generate ID
        String requestID = SAML2SDKUtils.generateID();
        xacmlQuery.setID(requestID);
        xacmlQuery.setVersion(SAML2Constants.VERSION_2_0);
        xacmlQuery.setIssueInstant(new Date());

        XACMLPDPConfigElement pdpConfig = getPDPConfig(realm, pdpEntityID);
        if (pdpConfig != null) {
          String wantQuerySigned =
              getAttributeValueFromPDPConfig(pdpConfig, "wantXACMLAuthzDecisionQuerySigned");
          if (wantQuerySigned != null && wantQuerySigned.equals("true")) {
            signAttributeQuery(xacmlQuery, realm, pepEntityID, false);
          }
        }

        String xmlString = xacmlQuery.toXMLString(true, true);
        if (debug.messageEnabled()) {
          debug.message(classMethod + "XACML Query XML String :" + xmlString);
        }
        // retrieve endpoint from meta data
        String endPoint = null;
        XACMLAuthzDecisionQueryConfigElement pepConfig = getPEPConfig(realm, pepEntityID);
        endPoint = getPDPEndPoint(pdpEntityID);
        if (debug.messageEnabled()) {
          debug.message(classMethod + " ResponseLocation is :" + endPoint);
        }
        // create SOAP message
        try {
          String soapMessage = SAML2SDKUtils.createSOAPMessageString(xmlString);

          endPoint = SAML2SDKUtils.fillInBasicAuthInfo(pepConfig, endPoint);
          String[] urls = {endPoint};
          SOAPClient soapClient = new SOAPClient(urls);
          if (debug.messageEnabled()) {
            debug.message(classMethod + "soapMessage :" + soapMessage);
          }
          InputStream soapIn = soapClient.call(soapMessage, null, null);
          StringBuffer reply = new StringBuffer();
          String line;
          BufferedReader reader = new BufferedReader(new InputStreamReader(soapIn, "UTF-8"));
          while ((line = reader.readLine()) != null) {
            reply.append(line).append("\n");
          }
          // check the SOAP message for any SOAP related errors
          // before passing control to SAML processor
          xmlString = reply.toString();
          if (debug.messageEnabled()) {
            debug.message("Response Message:\n" + xmlString);
          }

          samlResponse = getSAMLResponse(xmlString);

          issuer = samlResponse.getIssuer();
          String issuerID = null;
          if (issuer != null) {
            issuerID = issuer.getValue().trim();
          }
          boolean isTrusted = verifyResponseIssuer(realm, pepEntityID, issuerID);

          if (!isTrusted) {
            if (debug.messageEnabled()) {
              debug.message(classMethod + "Issuer in Request is not valid.");
            }
            String[] args = {realm, pepEntityID, pdpEntityID};

            LogUtil.error(Level.INFO, LogUtil.INVALID_ISSUER_IN_PEP_REQUEST, args);
            throw new SAML2Exception("invalidIssuerInRequest");
          }
          if (samlResponse != null) {
            xmlString = samlResponse.toXMLString(true, true);
            if (debug.messageEnabled()) {
              debug.message(classMethod + "Response: " + xmlString);
            }
            response = verifyResponse(realm, pepEntityID, samlResponse);
            if (debug.messageEnabled()) {
              debug.message(
                  classMethod
                      + "Response with decrypted Assertion: "
                      + response.toXMLString(true, true));
            }
          }

        } catch (SOAPException soae) {
          if (debug.messageEnabled()) {
            debug.message(classMethod + "SOAPException :", soae);
          }
          throw new SAML2Exception(soae.getMessage());
        } catch (Exception e) {
          if (debug.messageEnabled()) {
            debug.message(classMethod + "Exception ", e);
          }
          throw new SAML2Exception(e.getMessage());
        }
      }
    }
    return response;
  }