Esempio n. 1
0
  private void initPort(
      BindingProvider bindingProvider,
      String baseurl,
      SSLSocketFactory sslFactory,
      boolean soapMessage) {
    if (baseurl != null) {
      bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, baseurl);
      if (soapMessage) {
        List<Handler> handlerChain = new LinkedList<Handler>();
        handlerChain.add(new TraceHandler());
        bindingProvider.getBinding().setHandlerChain(handlerChain);
      }
    }

    // uncomment this lines if you what to use spécific keyStore and trustStore,
    // and not the default parameters from JVM. Do not forget to handle correctly
    // the exceptions.
    if (sslFactory != null) {
      try {
        bindingProvider.getRequestContext().put(JAXWSProperties.SSL_SOCKET_FACTORY, sslFactory);
      } catch (Exception ex) {
        // do something to log/track execptions
        ex.printStackTrace();
      }
    }
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    /*
     * Add client handler chain
     */
    BindingProvider bindingProvider = (BindingProvider) client;
    List<Handler> handlers = new ArrayList<Handler>(1);
    handlers.add(new JaxWSHeaderContextProcessor());
    bindingProvider.getBinding().setHandlerChain(handlers);

    /*
     * Lookup the DNS name of the server from the environment and set the endpoint address on the client.
     */
    String openshift = System.getenv("OPENSHIFT_APP_DNS");
    if (openshift != null) {
      bindingProvider
          .getRequestContext()
          .put(
              BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
              "http://" + openshift + "/RestaurantServiceAT");
    }

    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write(
        "<h1>Quickstart: This example demonstrates the deployment of a WS-AT (WS-AtomicTransaction) enabled JAX-WS Web service bundled in a war archive for deployment to *JBoss Enterprise Application Platform 6*.</h1>");

    System.out.println("[CLIENT] Creating a new WS-AT User Transaction");
    UserTransaction ut = UserTransactionFactory.userTransaction();
    try {
      System.out.println(
          "[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)");
      ut.begin();
      System.out.println("[CLIENT] invoking makeBooking() on WS");
      client.makeBooking();
      System.out.println(
          "[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)");
      ut.commit();

      out.write("<p><b>Transaction succeeded!</b></p>");

    } catch (Exception e) {
      e.printStackTrace();

      out.write("<p><b>Transaction failed with the following error:</b></p>");
      out.write("<p><blockquote>");
      out.write(e.toString());
      out.write("</blockquote></p>");
    } finally {
      rollbackIfActive(ut);
      client.reset();

      out.write(
          "<p><i>Go to your JBoss Application Server console or Server log to see the detailed result of the transaction.</i></p>");
    }
  }
Esempio n. 3
0
  /** Configures SOAP binding of the given SOAP port. */
  private void configureBinding(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;

    Map<String, Object> reqContext = bindingProvider.getRequestContext();
    reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);

    Binding binding = bindingProvider.getBinding();
    SOAPBinding soapBinding = (SOAPBinding) binding;
    soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom());
  }
Esempio n. 4
0
  public static void main(String args[]) throws Exception {
    VertragsService_Service vertragsServiceService = new VertragsService_Service();

    VertragsService vertragsService = vertragsServiceService.getVertragsServiceSOAP();
    BindingProvider provider = (BindingProvider) vertragsService;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(
        BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
        "http://localhost:8040/services/VertragsService");
    SOAPBinding binding = (SOAPBinding) provider.getBinding();
    binding.setMTOMEnabled(true);

    List<DataHandler> anlagen = new ArrayList<DataHandler>();
    DataSource ds = new FileDataSource(new File("PDFUserGuide.pdf"));
    DataHandler anlage = new DataHandler(ds);
    anlagen.add(anlage);
    vertragsService.anlegen("1", new Date(), anlagen);

    System.exit(0);
  }
Esempio n. 5
0
  public static void main(String[] args) throws SOAPException {
    // Service helloService = new HelloService();
    QName serviceName = new QName(targetNamespace, serName);
    QName portName = new QName(targetNamespace, pName);
    // Hello hello = helloService.getPortName();
    javax.xml.ws.Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    Dispatch<SOAPMessage> dispatch =
        service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    BindingProvider bp = (BindingProvider) dispatch;
    Map<String, Object> rc = bp.getRequestContext();
    rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, OPER_NAME);
    MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();

    SOAPMessage request = factory.createMessage();
    SOAPBody body = request.getSOAPBody();
    QName payloadName = new QName(targetNamespace, OPER_NAME, "ns1");
    SOAPBodyElement payload = body.addBodyElement(payloadName);
    SOAPElement message = payload.addChildElement(INPUT_NAME);
    message.addTextNode("x");
    //		String value = "<people>" +
    //				"<name>TimLu</name>"+
    //				"<age>26</age>"+
    //				"</people>";
    //		message.setValue(value);
    SOAPMessage reply = null;
    try {
      reply = dispatch.invoke(request);
    } catch (WebServiceException wse) {
      wse.printStackTrace();
    }
    SOAPBody soapBody = reply.getSOAPBody();
    SOAPBodyElement nextSoapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
    SOAPElement soapElement = (SOAPElement) nextSoapBodyElement.getChildElements().next();
    System.out.println("Return repsone value=" + soapElement.getValue());
  }
Esempio n. 6
0
  // don't think we ever need this as we get a registration port from the endpoint ref returned by
  // the activation port request
  public static ParticipantPortType getParticipantPort(MAP map, String action) {
    ParticipantService service = getParticipantService();
    ParticipantPortType port =
        service.getPort(ParticipantPortType.class, new AddressingFeature(true, true));
    BindingProvider bindingProvider = (BindingProvider) port;
    String to = map.getTo();
    List<Handler> customHandlerChain = new ArrayList<Handler>();
    /*
           * we no longer have to add the JaxWS WSAddressingClientHandler because we can specify the WSAddressing feature
    customHandlerChain.add(new WSAddressingClientHandler());
           */
    /*
     * we need to add the coordination context handler in the case where we are passing a
     * coordination context via a header element
     */
    customHandlerChain.add(new CoordinationContextHandler());
    bindingProvider.getBinding().setHandlerChain(customHandlerChain);
    Map<String, Object> requestContext = bindingProvider.getRequestContext();

    map.setAction(action);
    AddressingHelper.configureRequestContext(requestContext, map, to, action);

    return port;
  }
Esempio n. 7
0
 private void setHandlerChain(BindingProvider bp) {
   List<Handler> handlerChain = new ArrayList<Handler>();
   handlerChain.add(new MyHandler());
   bp.getBinding().setHandlerChain(handlerChain);
 }
Esempio n. 8
0
  public static updates.VersionInfo getWSVersionInfo(
      URL url, String GID, SK myPeerSK, Hashtable<Object, Object> context) {
    if (DEBUG_) System.out.println("call getWSVersionInfo on URL " + url);
    int i = url.toString().indexOf("&");
    if (i == -1) {
      if (DEBUG_) System.out.println("URL " + url + " has no PK hash");
      return null;
    }
    String PK_hex = url.toString().substring(i + 1);
    try {
      url = new URL(url.toString().substring(0, i));
    } catch (MalformedURLException ex) {
      System.out.println("error in url: " + url);
      return null;
    }
    if (DEBUG_) System.out.println("pk= " + PK_hex + "  url= " + url);
    DdWS service = new DdWS(url);
    if (DEBUG_) if (service == null) System.out.println("service=null");

    // service.getHandlerResolver().getHandlerChain(service.getDdWSPort()).add(new Handler());
    DdWSPortType DDver = service.getDdWSPort();
    // System.out.println("part: "+ service);

    BindingProvider bindingProvider = ((BindingProvider) DDver);

    List<javax.xml.ws.handler.Handler> handlerChain =
        bindingProvider.getBinding().getHandlerChain();
    Handler handler = new Handler();
    handler.setPK_Hex(PK_hex);
    handlerChain.add(handler);
    bindingProvider.getBinding().setHandlerChain(handlerChain);

    if (DEBUG_) if (DDver == null) System.out.println("DDver=null");
    // build history object
    Map<String, Object> c = bindingProvider.getRequestContext();
    Object URLloc = c.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    /* To change the location address
    *context.put(
      BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
      newAddress);
    */
    // System.out.println("loc: "+URLloc.toString());
    DateInfo d;
    if ((d = (DateInfo) context.get(url.toString())) == null) {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println(" Context = null");
      d = new DateInfo();
    } else {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println("localtime: " + d.LocalDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        System.out.println("Caltime: " + d.CalculatedDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        if (d.ServerDate != null) System.out.println("Servertime: " + d.ServerDate.getTime());
    }
    if (d.ServerDate != null) // server date set only with error
    d.CalculatedDate = getUpdateDate(d.ServerDate, d.LocalDate);
    d.ServerDate = null;
    String lDate = Util.getGeneralizedTime();
    d.LocalDate = Util.getCalendar(lDate);
    if (d.CalculatedDate == null) d.CalculatedDate = d.LocalDate;
    Request rq = new Request(GID, URLloc.toString(), d.CalculatedDate);
    String signature = Util.stringSignatureFromByte(rq.sign(myPeerSK));
    History h = new History();
    h.setGID(rq.peerGID);
    h.setUrl(rq.url);
    h.setDate(Encoder.getGeneralizedTime(rq.date)); // date as generalized for server side
    h.setSignature(signature);
    VersionInfo response = null;
    context.put(url.toString(), d);
    try {
      response = DDver.getVersionInfo(h);
    } catch (SOAPFaultException e) {
      if (DEBUG)
        System.err.println(
            "WSUpdate:HandleService:Code: "
                + e.getFault().getFaultCode()
                + ", Actor: "
                + e.getFault().getFaultActor()
                + ", String: "
                + e.getFault().getFaultString());
      if (e.getFault().getFaultActor().trim().equals("date")) {
        statusCode = INVALID_DATE;
        errorString = e.getFault().getFaultString();
        d = (DateInfo) context.get(url.toString());
        d.ServerDate = Util.getCalendar(errorString + ".000Z"); // Calendar.getInstance();
        context.remove(url.toString());
        context.put(url.toString(), d);
        // d.ServerDate.setTime(new Date(Long.parseLong(errorString)));
        if (DEBUG)
          System.out.println(
              "WSUpdate:HandleService:Server: "
                  + d.ServerDate.getTime()
                  + "  Client: "
                  + d.LocalDate.getTime());
      } else if (e.getFault().getFaultActor().trim().equals("url")) {
        statusCode = INVALID_URL;
        errorString = e.getFault().getFaultString();
      }
      return null;
    }
    statusCode = handler.isValidSignature();
    if (statusCode == INVALID_SIGNATURE) {
      return null;
    }
    updates.VersionInfo v = new updates.VersionInfo();
    v.version = response.getVersion();
    v.script = response.getScript();
    v.date = Util.getCalendar(response.getDate());
    // v.signature = Util.byteSignatureFromString(response.getSignature());
    v.data = new updates.Downloadable[response.getData().size()];
    Downloadable downloadable = null;
    for (i = 0; i < v.data.length; i++) {
      v.data[i] = new updates.Downloadable();
      downloadable = (Downloadable) response.getData().get(i);
      v.data[i].filename = downloadable.getFileName();
      v.data[i].url = downloadable.getUrl();
      v.data[i].digest = Util.byteSignatureFromString(downloadable.getDigest());
    }
    v.releaseQD = new data.D_ReleaseQuality[response.getQOTD().size()];
    TestDef testDef = null;
    for (i = 0; i < v.releaseQD.length; i++) {
      testDef = (TestDef) response.getQOTD().get(i);
      //	int index = testDef.getRef().intValue() - 1;
      int index = testDef.getRef().intValue();
      v.releaseQD[index] = new data.D_ReleaseQuality();

      v.releaseQD[index]._quality = new String[testDef.getQualityStructure().size()];
      for (int j = 0; j < v.releaseQD[index]._quality.length; j++) {
        v.releaseQD[index]._quality[j] = testDef.getQualityStructure().get(j);
      }
      v.releaseQD[index].description = testDef.getDesc();
    }

    v.testers_data = new data.D_SoftwareUpdatesReleaseInfoByTester[response.getTesters().size()];
    TesterInfo testerInfo = null;
    for (i = 0; i < v.testers_data.length; i++) {
      testerInfo = (TesterInfo) response.getTesters().get(i);
      v.testers_data[i] = new data.D_SoftwareUpdatesReleaseInfoByTester();
      v.testers_data[i].name = testerInfo.getName();
      v.testers_data[i].public_key_hash = testerInfo.getDigestPK();
      v.testers_data[i].tester_QoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      v.testers_data[i].tester_RoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      for (int j = 0; j < testerInfo.getTests().size(); j++) {
        // int index = ((Test)testerInfo.getTests().get(j)).getQualityRef().intValue() - 1;
        int index = ((Test) testerInfo.getTests().get(j)).getQualityRef().intValue();
        v.testers_data[i].tester_QoT[index] =
            ((Test) testerInfo.getTests().get(j)).getQoT().floatValue();
        v.testers_data[i].tester_RoT[index] =
            ((Test) testerInfo.getTests().get(j)).getRoT().floatValue();
      }
      v.testers_data[i].signature = Util.byteSignatureFromString(testerInfo.getSignature());
    }

    return v;
  }