Example usage for javax.xml.ws Service create

List of usage examples for javax.xml.ws Service create

Introduction

In this page you can find the example usage for javax.xml.ws Service create.

Prototype

public static Service create(QName serviceName, WebServiceFeature... features) 

Source Link

Document

Creates a Service instance.

Usage

From source file:GoogleSearch.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://api.google.com/GoogleSearch.wsdl");
    QName serviceName = new QName("urn:GoogleSearch", "GoogleSearchService");
    QName portName = new QName("urn:GoogleSearch", "GoogleSearchPort");
    Service service = Service.create(url, serviceName);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);

    SOAPMessage request = MessageFactory.newInstance().createMessage(null,
            new FileInputStream("yourGoogleKey.xml"));

    SOAPMessage response = dispatch.invoke(request);
    response.writeTo(System.out);
}

From source file:demo.wssec.client.Client.java

public static void main(String args[]) throws Exception {

    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);/*from w  w  w . j  a  va  2s .  c  o m*/
    }

    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = new ClassPathResource("wssec-client.xml").getURL();

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    Service service = Service.create(wsdlURL, SERVICE_NAME);
    Greeter port = service.getPort(PORT_NAME, Greeter.class);

    System.out.println("Invoking greetMe...");
    try {
        String resp = port.greetMe(System.getProperty("user.name"));
        System.out.println("Server responded with: " + resp);
        System.out.println();

    } catch (Exception e) {
        System.out.println("Invocation failed with the following: " + e.getCause());
        System.out.println();
    }

    System.exit(0);
}

From source file:eu.planets_project.ifr.core.servreg.utils.client.PlanetsCommand.java

/**
 * /*from   ww  w. j  a v  a  2s . c om*/
 * @param args
 */
public static void main(String[] args) {

    /* FIXME, point to log4j.properties instead of doing this? */
    /*
    java.util.logging.Logger.getLogger("com.sun.xml.ws.model").setLevel(java.util.logging.Level.WARNING); 
    java.util.logging.Logger.getAnonymousLogger().setLevel(java.util.logging.Level.WARNING);
    Logger sunlogger = Logger.getLogger("com.sun.xml.ws.model");
    sunlogger.setLevel(Level.WARNING);
    java.util.logging.Logger.getLogger( com.sun.xml.ws.util.Constants.LoggingDomain).setLevel(java.util.logging.Level.WARNING);
    */
    /* Lots of info please: */
    java.util.logging.Logger.getAnonymousLogger().setLevel(java.util.logging.Level.FINEST);
    java.util.logging.Logger.getLogger(com.sun.xml.ws.util.Constants.LoggingDomain)
            .setLevel(java.util.logging.Level.FINEST);
    // TODO See https://jax-ws.dev.java.net/guide/Logging.html for info on more logging to set up.
    //System.setProperty("com.sun.xml.ws.transport.local.LocalTransportPipe.dump","true");
    //System.setProperty("com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.dump","true");
    //System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump","true");
    // Doing this KILLS STREAMING. Log that.
    //System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump","true");

    URL wsdl;
    try {
        wsdl = new URL(args[0]);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return;
    }

    PlanetsServiceExplorer pse = new PlanetsServiceExplorer(wsdl);

    System.out.println(".describe(): " + pse.getServiceDescription());

    Service service = Service.create(wsdl, pse.getQName());
    //service.addPort(portName, SOAPBinding.SOAP11HTTP_MTOM_BINDING, endpointAddress)
    PlanetsService ps = (PlanetsService) service.getPort(pse.getServiceClass());

    // TODO The client wrapper code should enforce this stuff:
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) ps).getBinding();
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    ((BindingProvider) ps).getRequestContext().put(JAXWSProperties.MTOM_THRESHOLOD_VALUE, 8192);
    ((BindingProvider) ps).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    binding.setMTOMEnabled(true);
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    //System.out.println("Logging MTOM="+((BindingProvider)ps).getBinding().getBindingID()+" v. "+SOAPBinding.SOAP11HTTP_MTOM_BINDING);

    /* 
     * The different services are invoked in different ways...
     */
    if (pse.getQName().equals(Migrate.QNAME)) {
        System.out.println("Is a Migrate service. ");
        Migrate s = MigrateWrapper.createWrapper(wsdl);

        DigitalObject dobIn = new DigitalObject.Builder(Content.byReference(new File(args[1]))).build();

        MigrateResult result = s.migrate(dobIn, URI.create(args[2]), URI.create(args[3]), null);

        System.out.println("ServiceReport: " + result.getReport());

        DigitalObjectUtils.toFile(result.getDigitalObject(), new File("output"));

    } else if (pse.getQName().equals(Identify.QNAME)) {
        System.out.println("Is an Identify service. ");
        Identify s = new IdentifyWrapper(wsdl);

        DigitalObject dobIn = new DigitalObject.Builder(Content.byReference(new File(args[1]))).build();

        IdentifyResult result = s.identify(dobIn, null);

        System.out.println("ServiceReport: " + result.getReport());
    }
}

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * This class authenticates with the Hiperium Platform using JAXBContext and the selects user's home and
 * profile to access the system functions, and finally end the session. For all this lasts functions
 * we use SOAP messages with dispatchers and not JAXBContext.
 * // ww  w.j  av a  2 s.c  o  m
 * We need to recall, that for JAXBContext we could not add a handler to add header security parameters that need
 * to be verified in every service call in the Hiperium Platform, and for that reason, we only use JAXBContext in
 * the authentication process that do not need this header validation in the SOAP message header.
 * 
 * @param args
 */
public static void main(String[] args) {
    try {
        URL authURL = new URL(AUTH_SERVICE_URL);
        // The NAMESPACE must be http://authentication.soap.web.hiperium.com/ and must not begin
        // with http://SEI.authentication.soap.web.hiperium.com. Furthermore, the service name
        // and service port name must end WSService and WSPort respectively in order to call the service.
        QName authServiceQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSService");
        QName authPortQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSPort");
        // The parameter class must be annotated with @XmlRootElement in order to function
        JAXBContext jaxbContext = JAXBContext.newInstance(UserAuthentication.class,
                UserAuthenticationResponse.class);
        Service authService = Service.create(authURL, authServiceQName);
        // When we use JAXBContext the dispatcher mode must be PAYLOAD and NOT MESSAGE mode
        Dispatch<Object> dispatch = authService.createDispatch(authPortQName, jaxbContext,
                Service.Mode.PAYLOAD);
        UserCredentialDTO credentialsDTO = new UserCredentialDTO("andres_solorzano85@hotmail.com", "andres123");
        UserAuthentication authenticateRequest = new UserAuthentication();
        authenticateRequest.setArg0(credentialsDTO);
        UserAuthenticationResponse authenticateResponse = (UserAuthenticationResponse) dispatch
                .invoke(authenticateRequest);
        String sessionId = authenticateResponse.getReturn();
        LOGGER.debug("SESSION ID: " + sessionId);

        // Verify if session ID exists
        if (StringUtils.isNotBlank(sessionId)) {
            // Select home and profile
            URL selectHomeURL = new URL(HOME_SELECTION_SERVICE_URL);
            Service selectHomeService = Service.create(selectHomeURL,
                    new QName(AUTH_NAMESPACE, "HomeSelectionWSService"));
            selectHomeService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                    CLIENT_APPLICATION_TOKEN, AuthenticationObjectFactory._SelectHome_QNAME));
            Dispatch<SOAPMessage> selectHomeDispatch = selectHomeService.createDispatch(
                    new QName(AUTH_NAMESPACE, "HomeSelectionWSPort"), SOAPMessage.class, Service.Mode.MESSAGE);
            CommonsUtil.addSessionHeaderParms(selectHomeDispatch, sessionId);
            HomeSelectionDTO homeSelectionDTO = new HomeSelectionDTO(1L, 1L);
            SOAPMessage response = selectHomeDispatch.invoke(createSelectHomeSOAPMessage(homeSelectionDTO));
            readSOAPMessageResponse(response);

            // End Session
            URL endSessionURL = new URL(END_SESSION_SERVICE_URL);
            QName endSessionServiceQName = new QName(GENERAL_NAMESPACE, "MenuWSService");
            QName endSessionPortQName = new QName(GENERAL_NAMESPACE, "MenuWSPort");
            Service endSessionService = Service.create(endSessionURL, endSessionServiceQName);
            endSessionService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                    CLIENT_APPLICATION_TOKEN, GeneralObjectFactory._EndSession_QNAME));
            Dispatch<SOAPMessage> endSessionDispatch = endSessionService.createDispatch(endSessionPortQName,
                    SOAPMessage.class, Service.Mode.MESSAGE);
            CommonsUtil.addSessionHeaderParms(endSessionDispatch, sessionId);
            response = endSessionDispatch.invoke(createEndSessionSOAPMessage());
            readSOAPMessageResponse(response);
        }
    } catch (MalformedURLException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (JAXBException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:net.cloudkit.enterprises.ws.SuperPassParaProxyTest.java

public static void main(String[] args) throws Exception {

    // CodeLists_Const???XML?
    // MFT2008? RMFT8ChangeReasonCode (AlphaNumber)
    // 001   ?/*from  w  w w .  ja va  2s.  com*/
    // 002   
    // 003   ?
    // 004   ????
    // 005   ????
    // 006   ??????
    // 007   ????
    // 008   ????
    // 009   ??????
    // 010   ????
    // 011   ???
    // 012   ?
    // 013   ?
    // 014   ?
    // 015   ??
    // 999   
    //
    // MFT2008 RMFT8DeclareTypeCode (AlphaNumber)
    // MT1401   ??
    // MT2401   ???
    // MT5401   ??
    // MT5402   ??
    // MT3402   ?
    // MT7402   ??
    // MT8401   ??
    // MT8402   ??
    // MT8403   ???
    // MT8404   ???
    // MT4401   ??
    // MT4402   ??
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // MFT2008 RMFT8DeclareTypeCodeStat (AlphaNumber)
    // MT1401   ??
    // MT2401   ???
    // MT5401   ??
    // MT5402   ??
    // MT3402   ?
    // MT7402   ??
    // MT8401   ??
    // MT8402   ??
    // MT8403   ???
    // MT8404   ???
    // MT4401   ??
    // MT4402   ??
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // MFT2008 RMFT8FunctionTypeCode (AlphaNumber)
    // 2   
    // 3   
    // T   
    // 5   ?
    // 9   ???
    // 0   ???
    // 11   
    //
    // MFT2008 (AlphaNumber) RMFT8ReponseTypeCode
    // M1   M1-
    // M2   M2-??
    // M3   QP
    // 01   01-?
    // 02   02-
    // 03   03-?
    // 11   11-
    // 12   12-
    // 13   13-??
    // T   T-
    // D   D-?
    // E1   E1-??
    // E2   E2-?
    // E3   E3-??
    // E4   E4-?
    //
    // ?  (AlphaNumber) MasterAffirmSign
    // 0   
    // 1   ?
    // 2   ?
    //
    // ? ? (AlphaNumber) DeclareType
    // 0   
    // 1   
    //
    // MFT2008?? RMFT8MobileTypeCode (AlphaNumber)
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // ?  RMFT8MobileFuncCode (AlphaNumber)
    // M1   
    // M2   ??
    // M3   QP
    // 2   
    // 3   
    // T   
    // 5   ?
    // 9   ?
    // 0   (??)
    // 11   

    URL url = new URL("http://ceesb.chinaport.gov.cn/SuperPassParaProxy/Proxy_Services/SuperPass_Proxy?wsdl");
    QName qname = new QName("http://www.cneport.com/webservices/superpass", "SuperPass");
    Service service = Service.create(url, qname);
    SuperPass superPass = service.getPort(SuperPass.class);

    /*
    String serviceName = "eport.superpass.pub.para.CustomsFlagStatus";
    byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">c1f4bb</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"IcCode\">8800000246746</Key><Key name=\"OperatorName\"></Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>".getBytes();
    byte[] requestData = "<?xml version=\"1.0\"?>\n<CustomsFlagStatusRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<CustomsCode>5300</CustomsCode>\n</CustomsFlagStatusRequest>".getBytes();
    */

    // ??
    String serviceName = "eport.superpass.pub.para.LoadIntoMemory";
    byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">b6c29b</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"SessionId\">2015-7-14</Key><Key name=\"IcCode\">8910000270086</Key><Key name=\"OperatorName\">??</Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>"
            .getBytes();
    // ? MFT8TrayType
    // SELECT TRAY_CODE,TRAY_NAME FROM MFT8_TRAY_TYPE ORDER BY TRAY_CODE
    // ??? RMFT8TransportType
    // SELECT CODE, NAME FROM mft8_transport_type ORDER BY CODE
    // ? RMFT8CustomsCode
    // SELECT customs_CODE, customs_NAME FROM customs ORDER BY customs_CODE
    // ??(CN003) RMFT8PortCode
    // SELECT CODE, CHNAME FROM mft8_location_name ORDER BY CODE
    // ? RMFT8Curr
    // SELECT CODE, NAME FROM MFT8_ROAD_CURR ORDER BY CODE
    // ? RMFT8ReceiptPlace
    // SELECT CODE, NAME FROM mft8_entity ORDER BY CODE
    // ? RMFT8CountryCode
    // SELECT CODE, NAME FROM mft8_country_code ORDER BY CODE
    // ?? RMFT8CustomStatus
    // SELECT CODE, NAME FROM MFT8_ROAD_CUSTOMS_STATUS ORDER BY CODE
    // ?? RMFT8TransPayCode
    // SELECT CODE, NAME FROM MFT8_ROAD_PAYMENT_METHOD ORDER BY CODE
    // ??(CN005) RMFT8WrapTypeCode
    // SELECT CODE, NAME FROM mft8_packaging ORDER BY CODE
    // ??? RMFT8TransLicCode
    // SELECT CODE, NAME FROM MFT8_CONTR_CAR_COND ORDER BY CODE
    // ?? RMFT8PortWorkCode
    // SELECT CODE, NAME FROM MFT8_HAND_INSTR ORDER BY CODE
    // ?? RMFT8CommunicationCode
    // SELECT CODE, NAME FROM mft8_communi_type ORDER BY CODE
    // ? RMFT8PostCode
    // SELECT CODE, NAME FROM mft8_post_code ORDER BY CODE
    //  RMFT8EquipSizeCode
    // SELECT CODE, SHAPE,LENGTH,HEIGHT,WIDTH FROM mft8_equip_size_type ORDER BY CODE
    // ??? RMFT8EquipSupCode
    // SELECT CODE, NAME FROM MFT8_EQUIP_SUP ORDER BY CODE
    // ?? RMFT8EquipFullCode
    // SELECT CODE, NAME FROM mft8_equip_full ORDER BY CODE
    // ?? RMFT8EquipSealCode
    // SELECT CODE, NAME FROM mft8_seal_agency ORDER BY CODE
    // ??? RMFT8DanGoodsCode
    // SELECT CODE, CHNAME FROM mft8_dan_goods ORDER BY CODE
    // ? RMFT8CusProCode
    // SELECT CODE, NAME FROM mft8_cus_procedure ORDER BY CODE
    // ?/? RMFT8TransportSplitCode
    // SELECT CODE, NAME FROM mft8_indication ORDER BY CODE
    // ?? RMFT8DamageAreaCode
    // SELECT CODE, NAME FROM MFT8_DAMAGE_AREA ORDER BY CODE
    // ?? RMFT8DamageTypeCode
    // SELECT CODE, NAME FROM MFT8_DAMAGE_TYPE_DES ORDER BY CODE
    // IATA?(UN005) RMFT8IATACode
    // SELECT CODE, NAME FROM mft8_iata_code ORDER BY CODE
    // ????(UN009) RMFT8LocodePort
    // SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE
    // RMFT8ComplexCode
    // SELECT CODE_TS, G_NAME FROM complex ORDER BY CODE_TS
    byte[] requestData = "<?xml version=\"1.0\"?>\n<LoadIntoMemoryRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<QuerySql>SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE</QuerySql>\n</LoadIntoMemoryRequest>"
            .getBytes();

    Holder<byte[]> responseData = new Holder<byte[]>();
    System.out.println(new String(superPass.service(serviceName, requestContext, requestData, responseData)));

    // deflate 
    DeflateCompressorInputStream gis = new DeflateCompressorInputStream(
            new ByteArrayInputStream(responseData.value));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int count;
    byte data[] = new byte[1024];
    while ((count = gis.read(data, 0, 1024)) != -1) {
        baos.write(data, 0, count);
    }
    gis.close();

    data = baos.toByteArray();
    baos.flush();
    baos.close();

    System.out.println(new String(data));
    // System.out.println(new String(responseData.value, "UTF-8"));
}

From source file:eu.planets_project.tb.impl.services.wrappers.CompareWrapper.java

/**
 * //  w  w w  . j  av a2s.c  om
 */
private void init() {
    service = Service.create(pse.getWsdlLocation(), pse.getQName());
    try {
        c = (Compare) service.getPort(pse.getServiceClass());
    } catch (Exception e) {
        log.error("Failed to instanciate service " + pse.getQName() + " at " + pse.getWsdlLocation()
                + " : Exception - " + e);
        e.printStackTrace();
        c = null;
    }
}

From source file:eu.planets_project.tb.impl.services.wrappers.IdentifyWrapper.java

/**
 * /*from w w w. ja v  a 2s  .c  om*/
 */
private void init() {
    service = Service.create(pse.getWsdlLocation(), pse.getQName());
    try {
        i = (Identify) service.getPort(pse.getServiceClass());
    } catch (Exception e) {
        log.error("Failed to instanciate service " + pse.getQName() + " at " + pse.getWsdlLocation()
                + " : Exception - " + e);
        i = null;
    }
}

From source file:eu.planets_project.tb.impl.services.wrappers.MigrateWrapper.java

/**
 * //from   ww  w. j a v  a 2s . c o m
 */
private void init() {
    service = Service.create(pse.getWsdlLocation(), pse.getQName());
    try {
        m = (Migrate) service.getPort(pse.getServiceClass());
    } catch (Exception e) {
        log.error("Failed to instanciate service " + pse.getQName() + " at " + pse.getWsdlLocation()
                + " : Exception - " + e);
        m = null;
    }
}

From source file:eu.planets_project.tb.impl.services.wrappers.CharacteriseWrapper.java

/**
 * /*from   w w  w  .  ja  v a 2s . co  m*/
 */
private void init() {
    service = Service.create(pse.getWsdlLocation(), pse.getQName());
    try {
        c = (Characterise) service.getPort(pse.getServiceClass());
    } catch (Exception e) {
        log.error("Failed to instanciate service " + pse.getQName() + " at " + pse.getWsdlLocation()
                + " : Exception - " + e);
        e.printStackTrace();
        c = null;
    }
}

From source file:eu.planets_project.tb.impl.services.wrappers.CreateViewWrapper.java

/**
 * /*ww w .j  a  v  a 2 s . c om*/
 */
private void init() {
    service = Service.create(pse.getWsdlLocation(), pse.getQName());
    try {
        c = (CreateView) service.getPort(pse.getServiceClass());
    } catch (Exception e) {
        log.error("Failed to instanciate service " + pse.getQName() + " at " + pse.getWsdlLocation()
                + " : Exception - " + e);
        e.printStackTrace();
        c = null;
    }
}